* New additions to the list in relation to collection
* void Add (int index, Objectele): Adds an element at the specified index position index ele
Boolean addall (int index, Collection eles)
Object get (int index): Gets the element of the specified index
Object Remove (int index): Deletes the element at the specified index position
Object Set (int index, Objectele): Sets the element at the specified index position to Ele
int IndexOf (OBJECTOBJ): Returns the position of the first occurrence of obj in the collection. If not, return-1
int LastIndexOf (OBJECTOBJ): Returns the position of the last occurrence of obj in the collection. No, return-1
List sublist (int fromIndex, Inttoindex): Returns the left-hand side from FromIndex to the end of Toindex opens a sub list
List Common methods: Add (Object obj) Delete (remove) change (set (Intindex,object obj))
(Get (int index)) plug (add (int index, Object ele)) Length (size ())
1 @Test2 Public voidTestList2 () {3List List =NewArrayList ();4List.add (123);5List.add (456);6List.add (NewString ("AA"));7List.add (NewString ("GG"));8List.add (456);9System.out.println (List.indexof (456));TenSystem.out.println (List.lastindexof (456)); OneSystem.out.println (List.indexof (123) = = List.lastindexof (123)); ASystem.out.println (List.indexof (444)); - -List list1 = list.sublist (0, 3); the System.out.println (list1); - } - - @Test + Public voidTestList1 () { -List List =NewArrayList (); +List.add (123); AList.add (456); atList.add (NewString ("AA")); -List.add (NewString ("GG")); - System.out.println (list); -List.add (0,555); - System.out.println (list); -Object obj = list.get (1); in System.out.println (obj); -List.remove (0); toSystem.out.println (List.get (0)); +List.set (0, 111); -System.out.println (List.get (0)); the}
Java Learning--arraylist Use method: List of the main implementation class