Interview question: The difference between collection and collections in Java __java

Source: Internet
Author: User
1, Java.util.Collection is a Collection Interface。 It provides a common interface method for basic operations on a collection object. The collection interface has many specific implementations in the Java class Library.  The significance of the collection interface is to provide a maximum unified operation for a variety of specific sets. Collection
├list
│├linkedlist
│├arraylist
│└vector
│└stack
└set 2, Java.util.Collections is a packing class. It contains a variety of information about the collection operation. static Polymorphic method, which can be used to search, sort, and thread security of various sets. This class cannot be instantiated, just like a a tool class, and serves the collection framework of Java.

Import java.util.ArrayList;
Import java.util.Collections;
Import java.util.List;

public class Testcollections {

public static void Main (String args[]) {
Note that the list is implemented with the collection interface
List List = new ArrayList ();
Double array[] = {112, 111, 23, 456, 231};
for (int i = 0; i < Array.Length; i++) {
List.add (New Double (Array[i]));
}
Collections.sort (list);
for (int i = 0; i < Array.Length; i++) {
System.out.println (List.get (i));
}
Results: 23.0 111.0 112.0 231.0 456.0
}
}

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.