The class set in Java

Source: Internet
Author: User

The first thing to understand is what is called a class set, and what is its role?

The class set is actually a dynamic array of objects, and someone will ask, isn't there an array? What about the class set, actually Ah, the general array has a length limit no, the class set is specifically to solve this limitation, using the class set can easily add any number of data to the array, it is easy to expand and modify.

Let's learn about the schema of the class set, where all class set operations are stored in the Java.util package:


The collection interface is the largest parent interface for storing single-valued collections, but in general development it is not developed directly with collection (the operational meaning is ambiguous), but is developed using its sub-interfaces.


The contents of the list interface allow repetition.

ArrayList is the most commonly used subclass in the list, and is an array-based operation class. You can either increase the data or delete the data. Deletions can be removed in two ways: Depending on the object's content, the corresponding number of the object is deleted.

LinkedList is also a subclass of list, and is a linked list-based operation class.

Vector is also a subclass of list, and it differs from ArrayList in:


Duplicate elements are not allowed in the set interface, and commonly used subclasses have TreeSet (ordered storage), HashSet (hash).

TreeSet can be sorted, so what is the principle of sorting it? To sort an array of objects, it relies on the comparable interface to complete. So for TreeSet, the class where the object resides must also implement the comparable interface and overwrite the CompareTo method.


What is the principle of repeating elements not allowed in the set interface? By covering the hashcode () and Equals () two methods in the object class, it is possible to make a repetition of the objects ' elements. Not to be continued ...

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The class set in Java

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.