Collection
* Collection Interface
* List interface: stored in an orderly, repeatable element
* ArrayList (the main implementation class is the underlying implementation is an array), LinkedList (the underlying implementation is a list), Vector (Old implementation class JDk1.0, thread-safe but inefficient)
* Set interface: Stores unordered, non-repeatable elements
* HashSet, Linkedhashset, TreeSet
* MAP: Stores data for "key-value" pairs
* HashMap, Linkedhashmap, TreeMap, Hashtable (-properties)
Importjava.util.ArrayList;Importjava.util.List;Importorg.junit.Test; Public classtestlist {@Test Public voidtestList2 () {List List=NewArrayList (); List.add (123); List.add (NewString ("AA")); SYSTEM.OUT.PRINTLN (list); System.out.println (List.indexof (123)); System.out.println (List.lastindexof (123)); System.out.println (List.indexof (123) ==list.lastindexof (123)); List List1= List.sublist (1, 2); System.out.println (List1); } @Test Public voidTestList1 () {List List=NewArrayList (); List.add (123); List.add (NewString ("AA")); SYSTEM.OUT.PRINTLN (list); List.add (0, 555); SYSTEM.OUT.PRINTLN (list); Object obj= List.get (1); System.out.println (List.get (0)); List.set (0, 888); System.out.println (List.get (0)); SYSTEM.OUT.PRINTLN (list); System.out.println (List.size ()); }}
List Common methods: Add: (Add ()) Delete: (remove ())
* Change: (set (int index,object elem)) Check: (Get (int index))
* Plug (add (int index,object elem)) Length (size ())
* int indexOf (Object obj): Returns the position of the first occurrence of obj in the collection, if no return-1
* int lastIndexOf (Object obj): Returns the position of the last occurrence of obj in the collection, if no return-1
* List sublist (int fromindex,int toindex); Returns a sub List from FromIndex to Toindex
Java Learning Diary------Collection