The difference between collection and collections in Java

Source: Internet
Author: User

Today, look at the Java pen Test, found that there is such a problem, compare collection and collections differences. Keep a record of the differences here.

1, Java.util.Collection is a collection interface . It provides a common interface method for basic manipulation of collection objects. The collection interface has many specific implementations in the Java class Library. The meaning of the collection interface is to provide a maximum unified operation for a variety of specific collections.

Collection
├list
│├linkedlist
│├arraylist
│└vector
│└stack
└set

2, Java.util.Collections is a packaging class. It contains a variety of static polymorphic methods related to set operations. This class cannot be instantiated , just like a tool class that serves the Java collection framework.

Java code 650) this.width=650; "class=" star "src=" Http://pengcqu.iteye.com/images/icon_star.png "alt=" Favorite Code "style=" border:0px; "/>

  1. import java.util.ArrayList;

  2. import java.util.Collections;

  3. import java.util.List;

  4. Public class testcollections {

  5. Public Static void Main (String args[]) {

  6. //Note that the list is implemented with the collection interface

  7. List List = new ArrayList ();

  8. double array[] = { 111, 456, 231 };

  9. for (int i = 0; i < array.length; i++) {

  10. List.add (new Double (Array[i]));

  11. }

  12. Collections.sort (list);

  13. for (int i = 0; i < array.length; i++) {

  14. System.out.println (List.get (i));

  15. }

  16. //Result: 23.0 111.0 112.0 231.0 456.0

  17. }

  18. }


The difference between collection and collections in Java

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.