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