Collection: A type used to hold multiple elements.
Framework: is a structural system composed of many classes.
The following is a description of the two commonly used collection frameworks (collection collections and map collections).
650) this.width=650; "Title=" collection Collection "alt=" Wkiol1em2gsaz8rgaacwnbqpje4625.jpg "src=" http://s2.51cto.com/ Wyfs02/m00/84/51/wkiol1em2gsaz8rgaacwnbqpje4625.jpg "/>
Collection is a single-column collection, it is an interface, it mainly has a list and set two sub-interfaces, the list sub-interface contains ArrayList, LinkedList and vector concrete implementation class The set sub-interfaces are mainly hashset and treeset specific implementation classes. Where the list interface is indexed, and the set interface is not indexed; The elements inside the hashset are ordered, and the elements inside the TreeSet are unordered.
-
ArrayList: Dynamic array, indicating variable length of array;
-
Arraylist,linkedlist uses exactly the same way, the difference is that the data is stored in different ways, called different data structures;
-
ArrayList: Based on the implementation of the array (advantages: continuous storage, find faster, the disadvantage is to increase the element or delete the element is relatively slow);
-
LinkedList: Based on the link list implementation (disadvantage: discontinuous storage, the search speed is relatively slow, the advantages: add elements or delete elements faster).
-
Vector vectors: Based on arrays, but obsolete, now with ArrayList.
An example of a ArrayList:
To create a class test:
public class Test {
public static void Main (string[] args) {
Arraylist<string> al=new arraylist<string> ();
Al.add ("Beijing");
Al.add ("Tianjin");
Al.add ("Shanghai");
Al.add (1, "Guangzhou");//Add an element to the position of index 1 Guangzhou
Show1 (AL);
Al.set (1, "Guangzhou");//Modify the element at index 1 to Guangzhou
System.out.println ("*****************");
Show2 (AL);
System.out.println ("*****************");
Al.remove (2);//delete element with index 2, i.e. Tianjin, element index starting from 0
Show2 (AL);
}
Method One: For loop
public static void Show1 (Arraylist<string> al)
{
for (int i=0;i<al.size (); i++)
{
System.out.println (Al.get (i));
}
}
Method Two: Iterator Walker traversal
public static void Show2 (Arraylist<string> al)
{
Iterator<string> it=al.iterator ();//equivalent to an element pointer
while (It.hasnext ())//Judging there is no next
{
System.out.println (It.next ());
}
}
}
Run result 650) this.width=650; "title=" Run Result "alt=" wkiom1em3nxi8kyiaaawp9fo5xm182.jpg "src=" http://s3.51cto.com/wyfs02/ M01/84/51/wkiom1em3nxi8kyiaaawp9fo5xm182.jpg "/>
The next blog post introduces the Map collection 650) this.width=650; "alt=" I_f01.gif "src=" Http://img.baidu.com/hi/face/i_f01.gif "/>
This article is from the "John" blog, make sure to keep this source http://zyh928.blog.51cto.com/9467544/1827532
Java Collection Framework