List, Set Description
- java.util.ArrayList set of stored data structure is an array structure. Elemental additions and deletions slow, fast lookup
- java.util.LinkedList data storage structure is a set of linked list structure. Convenient element to add, delete collections
- java.util.LinkedHashSet, it is a data storage structure list and hash table combination. Ordered
- java.util.HashSet is an implementation of the Set interface, its stored element is not repeatable, and (i.e., inconsistent access sequence) elements are disordered. Java.util.HashSet achieve the underlying fact is supported by a java.util.HashMap
Collentions Tools
method:
- public static <T> boolean addAll (Collection <T> c, T ... elements): add some elements to the collection.
- public static void shuffle (<?> List list) out of order: disrupt the order of collection.
- public static <T> void sort (List <T> list): The elements in the set according to the default ordering rules.
- public static <T> void sort (List <T> list, Comparator <super T?>): The elements in the collection sorted according to the specified rules.
addAll Case:
private static void addAll() { ArrayList<Integer> list = new ArrayList<>(); list.add(1); list.add(2); list.add(3); System.out.println("list1"+list); Collections.addAll(list, 4, 5, 6); System.out.println("list2"+list); } //list1[1, 2, 3] //list2[1, 2, 3, 4, 5, 6]
Sort function:
/ ** * get the first character in descending order * / Private static void collecyionsSort () { the ArrayList <String> List = new new the ArrayList <> (); Collections.addAll (List, "ha", "weeping" "hee" ); the Collections.sort (List, new new Comparator <String> () { @Override public int Compare (String O1, O2 String) { return o2.charAt (0) -o1.charAt (0 ); } }); System.out.println ( "List =" + List); } // list = [hee, weeping, ha ha]