Java Review-Collection

Source: Internet
Author: User

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

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.