1. Features of the list collection
The list itself is also an interface, as follows:
1 Public Interface List<e> extends collection<e>
(1) List is an ordered collection (also known as a sequence), where the user of this interface can precisely control where each element in the list is inserted, and the user can access the element based on the integer index of the element (in the list) and search for the elements in the list.
(2) Unlike set,list lists usually allow repeating elements .
2. code example:
1 Packagecn.itcast_01;2 3 Importjava.util.ArrayList;4 ImportJava.util.Iterator;5 Importjava.util.List;6 7 /*8 * Features of the list collection:9 * Ordered (same as stored and removed elements), repeatable. Ten */ One Public classListDemo2 { A Public Static voidMain (string[] args) { - //To create a collection object -List List =NewArrayList (); the - //Storage Elements -List.add ("Hello"); -List.add ("World"); +List.add ("Java"); -List.add ("Java ee"); +List.add ("Android"); AList.add ("Java ee"); atList.add ("Android"); - - //iterating through the collection -Iterator it =list.iterator (); - while(It.hasnext ()) { -String s =(String) It.next (); in System.out.println (s); - } to } +}
The results are as follows:
Java Basic Knowledge Enhancement Collection Framework note 15:list Collection features