Java --list common method summary

Classes in java.util * Import;. 

public class ListTest { 
    public static void main (String [] args) { 
        List List new new = the ArrayList (); 
        List.add ( "A"); // added to the collection element 
        List.add ( 1, "b"); // additional elements to customize the position of the collection 
        list.addAll (list); // set to append a collection, only the collection can be added, because of the java collection is not available to achieve, by its lower interfaces achieved 
        list.addAll (4, list); // same as above, "4" means the position of the additional elements put 
        int i = list.size (); // length 
        System.out.println (i); 
        list.get (0); // get a collection of elements to the elements in accordance with the subscript 
        list.remove (7); // removing elements according to the position of the elements of the set standard 
        // this method is used to compare with the equals similar, list element now has [a, b, a, b , a, b, a], and to "a, b, c" Comparative returns to false; 
        // but note again used to compare strings string returns true of the case where the local time of comparison, the same string two portions 
        list.contains ( "a, B,c");
        // To List into an array, JDK provides toArray 
        // implementation of a: 
        String [] = Array (String []) List.toArray (new new String [list.size ()]); 
        for (String Arrays: Array ) { 
            System.out.println (Arrays); 
        } 

        // Second way 
        String [] = ARR new new String [list.size ()]; 
        List.toArray (ARR); 
        for (String ARRS: ARR) { 
          the System.out. the println (ARRS); 
        } 
        // determines whether the set is empty, not empty returns false, empty returns true, and often null! = list to jointly determine whether the collection is empty, 
        // null! = list and list.isempty biggest difference is: a man to drink, the former judge whether there is glass, which is to determine whether the glass of water 
        System.out.println (list.isEmpty ()); // false 
        System. out.println (null = list!); // true 
        // The method to compare two objects, first of all go to determine if two objects have the same address, if the same object is referenced, directly back into the true; if the address is not the same, 
        // the same reference not proved an object, one by one, the next step is to compare the contents of two string objects are the same, exactly equal returns true, otherwise false. 
        // this will involve hashcode content, I will open a separate introduce 
        list.equals (arr); // false 
        // find elements in the collection, "a" if you have to return to find elements of the index, If there are no -1 is returned 
        list.indexOf ( "a"); 
        // set the print elements 
        @ a way: 
        the Iterator list.iterator IT = (); 
        the while (it.hasNext ()) { 
            String = String (String) it.next (); 
            System.out.println (String); 
        } 
        // Second way: 
        for (Object O: List) { 
            System.out.println (O); 
        } 
        // three ways:
        for (int = S 0; S <list.size (); S ++) { 
            System.out.println (List.get (S));
        } 
        // release the list, empty elements, and no return value 
        list.clear (); 
        System.out.println (list); 
        

    } 
}

  

 

Guess you like

Origin www.cnblogs.com/ppp1314520818/p/12535909.html