Collections and Collection of difference

java.util.Collections is a collection of tools, can not be instantiated, for the collection operation, the Collection is a collection of interfaces, apply List, Set.

Collections common methods are as follows:

public static <T> boolean addAll (Collection <T> c, T ..... elements): add some elements to the collection.

public static void shuffle (List list <?>): upset collection order.

public static <T> void sort (List <T> list): The elements of a 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.

Use the following:

ArrayList<Integer> list = new ArrayList<Integer>();

// The original wording

//list.add(12);

//list.add(14);

//list.add(15);

//list.add(22);

Using completion tools // add elements to the collection

Collections.addAll(list, 5,222,1,2);

sout(list);

// sort method

Collections.sort(list);

, A method want to change it if you want to specify the order (order, reverse order) with the default sort when sorting such a manner as described above.

public static <T> void sort (List <T> list, Comparator <super T?>): The elements in the collection sorted according to the specified rules.

Comparator comparator

Published 98 original articles · won praise 43 · views 30000 +

Guess you like

Origin blog.csdn.net/qq_42352666/article/details/104758375