Define the list and put the array in it:
list<integer> temp = new arraylist<integer> ();
list<string> temp = new arraylist<string> ();
Get the number of elements in the set: List.size ();
To add an element:
Default add: List.add (e);
Specify the subscript to add (after adding the element after subscript, move one bit backwards): List.add (index,e);
If we get the list also want to delete, then you can use the AddAll method
string[] str = {"1", "2", "3",};
list<string> Strarray = new arraylist<string> ();
Strarray.addall (Arrays.aslist (str));
Strarray.add ("a");
System.out.println (Strarray);
The result is: 1 2 3 A
To delete an element:
Returns whether deleted: List.remove (e);
Delete the element that specifies the subscript directly (delete only the first matching element found): List.remove (index);
Replace element (replaces the element with the specified subscript): List.set (index,e);
remove element: List.get (index);
Empty collection: List.clear ();
Determines whether an element exists in the collection (there is a return of true, there is no return false): List.contains (e);
Compare all the elements in two collections:
Two objects must be equal: List.equals (LIST2);
Two objects are not necessarily equal: list.hashcode () = = List2.hashcode ();
(The Equals method of two equal objects must be true, but two hashcode equal objects are not necessarily equal.) )
Get the element subscript:
The element exists then returns the subscript of the first element found, and returns -1:list.indexof (e) If it does not exist;
The element exists then returns the subscript of the last element found, and returns -1:list.lastindexof (e) If it does not exist;
Determines whether the collection is empty (null returns TRUE, non-null returns FALSE): List.isEmpty ();
Returns the Iterator Collection object: List.iterator ();
Converts a collection to a string: list.tostring ();
Intercept collection (starting from FromIndex in front of Toindex, [Fromindex,toindex)): List.sublist (Fromindex,toindex);
To convert a collection to an array:
Default type: List.toarray ();
Java------List Usage