Java Collection framework learning note set and Collection API

Source: Internet
Author: User

1. CollectionAPI

A Collection is a Collection of objects ). Collections are an important data interface in programming. Java provides a collection class library called CollectionAPI.

A set uses an object to represent a group of objects. Each object in the set is called an element. The specific types of each element in the set can be different, but generally they are derived from the same class (and this is not difficult to do, because all classes in Java are subclasses of objects ). When retrieving each element from a set, it is often necessary to perform corresponding forced type conversion based on its specific type.

The interfaces and classes in the Collection API are mainly unique in the java. util package. The most basic interface is Collection, which organizes a group of objects in the form of Collection elements and implements different organization methods in its subinterfaces. There are two subinterfaces for Collection.

Set: the sequence in which elements are stored is not recorded, and repeated elements are not allowed;

List: Record elements are kept in order and repeated elements are allowed.

The reuse implementation class of the Set interface includes HashSet ). Important implementation classes of the List interface include ArrayList, List, and Vector.

Shows the relationship between them.


Collection and its sub-interfaces List and Set



Ii. Collection interface and Method

The Collection interface has the following important methods:

Public boolean add (Object o); // add an element

Public boolean remove (Object o); // remove an element

Public void clear (); // clear all elements

Public boolean contains (Object o); // determines whether an element is contained.

Public int size (); // number of elements

Public boolean isEmpty (); // determines whether it is null.

Public Iterator iterator (); // get the Iterator




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.