The collection of Java is broadly divided into the following types of map set list queue
Set represents unordered, non-repeatable collection
The list represents an ordered, repeating set
Map represents a collection of mapping relationships
A queue represents a collection of queues
As we can see from the above figure, when we access the set set we can only access it according to the element itself, access the list collection directly according to the index of the element, if you access the elements in the map collection, you can access the element according to the key value of each key, collection is the list map The parent interface of the queue, the method defined in the interface, can manipulate the set map queue
Package mypackage;
Import java.util.ArrayList;
Import java.util.Collection;
public class MyCollection {
public static void Main (string[] args) {
Collection collection=new ArrayList ();
Collection.add ("Lee");
Collection.add (7);
System.out.println (Collection.size ());
System.out.println (Collection.contains (7));
Collection.add ("This is a Beautiful Morning");
System.out.println (collection);
System.out.println (Collection.tostring ());
System.out.println (Collection.toarray () [1]);
}
}
2
True
[Lee, 7, this is a beautiful morning]
[Lee, 7, this is a beautiful morning]
7
Package mypackage;
Import java.util.ArrayList;
Import java.util.Collection;
Import Java.util.HashSet;
public class MyCollection {
public static void Main (string[] args) {
Collection collection=new ArrayList ();
Collection.add ("Lee");
Collection.add (7);
System.out.println (Collection.size ());
System.out.println (Collection.contains (7));
Collection.add ("This is a Beautiful Morning");
System.out.println (collection);
System.out.println (Collection.tostring ());
System.out.println (Collection.toarray () [1]);
Collection bookscollection=new HashSet ();
Bookscollection.add ("Java");
Bookscollection.add ("PHP");
System.out.println (bookscollection);
Bookscollection.clear ();
System.out.println (bookscollection);
}
}
Java Review-Collection