List interface Overview (its elements can be duplicated)
the Orderly collection (also known as a sequence ). Users of this interface can precisely control the insertion position of each element in the list. The user can access the element based on the integer index of the element (where it is located in the list) and search for the elements in the list.
Unlike set, a list usually allows repeating elements.
List case
Store strings and Traverse
Store custom objects and traverse
Package cn.itcast_01;
Import java.util.ArrayList;
Import Java.util.Iterator;
Import java.util.List;
/*
* features of the list collection:
* ordered (same as stored and removed elements), repeatable.
*/
public class ListDemo2 {
public static void Main (string[] args) {
To create a collection object
List List = new ArrayList ();
Storage elements
List.add ("Hello");
List.add ("World");
List.add ("Java");
List.add ("Java ee");
List.add ("Android");
List.add ("Java ee");
List.add ("Android");
Iterating through the collection
Iterator it = List.iterator ();
while (It.hasnext ()) {
string s = (string) it.next ();
System.out.println (s);
}
}
}
This article from "GD" blog, reproduced please contact the author!
Collection Framework (features of the list collection)