java-Collection (v)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.