All things in Java are objects, data is encapsulated into classes, classes create objects, and containers are similar to arrays that hold objects. The container has the following characteristics than the array: 1, the container length is variable, the array is fixed in the heap memory, and 2, the container can hold different types of objects, and the array element types should be indicated when they are created. Two points in the final analysis, the existence of an array must be allocated at the beginning of creation and cannot be changed.
Set as a tool, stored in the Java.util package. Its top-level features are encapsulated by the interface collection. The following is an example of its basic method (because the interface needs to override its methods after inheritance, so use the ArrayList class that implements the interface instead).
Import java.util.*;p Ublic class Demo1 {public static void-out (Object obj) {System.out.println (obj);} public static void Main (string[] args) {ArrayList Al = new ArrayList ();/* Add Data Method Add () */al.add ("Collection1"); Al.add (" Collection2 "), Al.add (" Collection3 "), Al.add (" Collection4 ");/* Delete element */al.remove (2);/* Set length */out (" Al.size: "+al.size ( );/* Set Element */out (AL);}}
Operation Result:
Al.size:3
[Collection1, Collection2, Collection4]
It is important to note that the collection does not hold all of the objects stored in the collection, but is a reference to the object, that is, the address.
Java collection classes