Collectionscollections: Its presence provides more functionality to the set operation. This class does not need to create objects, and internally provides static methods. Static methods: Collections.sort (list);//list sets the natural ordering of elements. Collections.sort (List,new Comparatorbylen ());//Sort by the specified comparer method. Class Comparatorbylen implements Comparator<string>{public int compare (String s1,string s2) {int temp = S1.length () -s2.length (); return temp==0 S1.compareto (S2): temp; }}collections.max (list);//returns the element with the largest dictionary order in the list. int index = Collections.binarysearch (list, "zz");//binary lookup, returns the corner label. Must be an ordered collections.fill ();//You can replace all the elements in the list collection with the specified elements. Collections.repalceall (list, "to be replaced", "substituted value");//You can replace the specified element in the list collection with the specified element. Collections.reverse (); Invert Collections.reverseorder (the parameter is the comparator);//reverse-reverse sort. Reverse: Collections.shuffle (list);//random displacement of the position of the elements in the list. To convert a non-synchronous collection to a synchronous collection: XXX synchronizedxxx (XXX) in collections; List synchronizedlist (list); Map Synchronizedmap: Defines a class that adds all the methods of the collection to the same lock and returns. The difference between Collection and collections: Collections is a java.util class, a tool class for a collection class that provides a series of static methods for finding, sorting, replacing, Thread-safe operations such as converting a non-synchronized collection to synchronous. Collection is a Java.util interface, which is the parent interface of various collection structures, and the interfaces that inherit from it are mainly set and LIST, which provides some operations on the collection, such as inserting, deleting, judging whether an element is a member, traversing, and so on.
Java-Collection (v)