A set of Java knowledge

of java.util.ArrayList Import; 

/ *
length of the array is not altered
but the length can be freely set ArrayList changed

for ArrayList, there is a angle bracket <E> Representative generic
generic: which is mounted in the collection All the elements are all unified type of
generic types can not only be a reference to the basic type


* /
public class Arraylist {
public static void main (String [] args) {
// create an ArrayList collection, name of the collection is a list inside string string is filled with all types of data

ArrayList <string> list = new ArrayList <> (); // Create a set of string type is stored
instead of the address value is set ArrayList // for direct printing content but obtained If the content is empty is obtained empty brackets
System.out.println (List); // []

// add to the collection of data which need to use some of the add method
list.add ( "Zhao Liying");
List.add ( "now Lee");
//list.add(100);// which can add a set of string type that is set by the nature of the decision and
If you want to set basic types of data stored in the ArrayList must use substantially corresponds to the type "packaging" 

System.out.println(list);

}
}

Guess you like

Origin www.cnblogs.com/miaosixian/p/11571620.html