Collection and Map and collections

Source: Internet
Author: User

The difference between the two:

Both are interfaces;

Collectoin is a top-level interface of the Java Collection framework, and the stored elements can be any type of object;

Map is a map interface of the Java collection framework that stores objects in the form of key-value pairs;

That is, the element stored in collection is an object, and map is the stored element that is a pair of pair of key-value pairs.

Collection<stirng> c=new arraylist<string> ();

Map<integer,string> map=new haspmap<integer,string> ();

C.add ("Hello");

C.add ("World");

Map.put (1, "Beijing");

Map.put (2, "tianjing");

Collection and Collections (class, All methods are static, the parameters of the method are all collections, so it is used to manipulate the array)

Collection<stirng> c=new arraylist<string> ();

Arraylist<string> list=new arraylist<stirng> ();

List.add ("Hello");

List.add ("etc");

Collections.sort (list);//Because collections is a class, and all methods are static, you can call a static method directly using the class name

for (stirng s:list) {

System.out.println (s);

}

Results: etc

Hello

Answer:

Collection cannot create objects directly, you can use their implementation classes to create a pair of images;

Collections is a Java collection framework of a class, is a tool class, defines a lot of static methods, you can manipulate the collection object;

Collection and Map and collections

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.