import java.util.arraylist;import java.util.iterator;import java.util.linkedlist;import Java.util.list;public class listtest01 {/* *list Collection Storage element features: 1. Ordered (the list is stored with subscript): This is the order in which they are taken out or taken out in this order. 2. Repeatable */public static void main (String[] args) {//Create a list collection. List l = new arraylist ();//Add L.add (+), L.add (L.add); L.add (+); L.add (250);//Traverse iterator it = l.iterator (); while (It.hasnext ()) {System.out.println (It.next ());} /* * arraylist the bottom of the collection is an array. The array is labeled. So the ArrayList collection has a lot of its own features. ArrayList collection The underlying default initialization capacity is 10. The capacity after enlargement is 1.5 times times that of the original capacity. Vector collection The underlying default initialization capacity is also 10. The capacity after enlargement is twice times the original capacity. If you optimize ArrayList and vectors, try to minimize the scaling operation, because the expansion requires an array copy. Array copies consume memory. It is generally recommended to specify the initialization capacity when creating the collection. *///Create List collection//list l = new arraylist (); List l1 = new linkedlist ();//add Element L1.add (123); L1.add (321); L1.add (69);//Add 555l1.add at position subscript 1 (1,555); //obtains the first element System.out.println (l1.get (0)); SyStem.out.println ("===========================");//traversal (unique traversal method of the list collection) for (Int i=0;i<l1.size (); i++) {Object element = l1.get (i); SYSTEM.OUT.PRINTLN (element);} Iterators can also}}
This article is from the "Gaogaozi" blog, make sure to keep this source http://hangtiangazi.blog.51cto.com/8584103/1669557
List collection in Java