[Java class set] _ recognition class set and collection interface notes

Source: Internet
Author: User

[Java class set] _ recognition class set and collection interface notes

3. Details

Function of Class Set

A class set is actually a dynamic array of objects. unlike an ordinary array of objects, the content of the class set objects can be expanded at will.

Features of a class set:
1. This framework is of high performance.
2. The framework must allow different types of class sets to work in the same and highly interoperable manner
3. The class set must be easily extended and modified.

The object array contains a group of objects, but there is a length limit when using the object array. The class set specifically addresses this restriction, you can use the class set to conveniently add any number of data to the array.
In object Array Operations, object type consistency must be basically ensured. For the class set, its internal elements should also be consistent, no matter what type of data, all operations should be the same.

Main interfaces of the class set framework

No. Interface Description
1 collection is the maximum interface for storing a set of single values. The so-called single value means that each element in the set is an object, which is rarely directly used for direct operation.
2 list is a sub-interface of the collection interface, and is also the most common interface. This interface is used to expand the collection, and the content in it can be repeated.
3. Set is a sub-interface of the collection interface. The collection interface is not extended and duplicate content cannot be stored in it.
4 map is the largest interface for storing a pair of values. Each element in the interface is a pair, which is saved as key-> value.
5. The output interface of the iterator set is used to output the content in the set. Only one-way output from front to back can be performed.
6 listiterator is a sub-interface of iterator and can be output in two directions.
7. enumeration is the earliest output interface used to output the specified content in the collection.
8 sortedset: The sortedset class that implements the sortedset Single-value sorting interface. The content in the sortedset class can be sorted by the comparator.
9 sortedmap stores a sorting interface of values to implement the collection class of this interface. The content in the interface is sorted by key and sorted by comparator.
10 queue interface. sub-classes of this interface can implement queue operations (FIFO, first-in-first-out)
11 Internal interface of map. Entry map. Entry, each map. Entry object stores a pair of key-> value content, and each map interface stores multiple map. Entry interface instances.

All the above interfaces must be mastered and master the main features of each interface.

Interface inheritance

Collection interface:

Collection
List set queue sortedset

Map interface:

Map
Sortedmap

Collection Interface Definition

Collection is the maximum parent interface for saving a single value set.
Collection interface definition:
Public Interface collection <E> extends iterable <E>

Added a generic declaration for the Collection interface after jdk1.5

All class set operations are stored in the Java. util package.

Method definition of the collection interface.

No. method type description
1 Public Boolean add (e o) insert objects to the set
2 Public Boolean addall (collection <? Extend E?> C) Insert the content of a set
3 Public void clear () is used to understand all elements in this set.
4 Public Boolean contains (Object O): determines whether an object exists in a collection.
5 Public Boolean containsall (collection <?> C) check whether a group of objects exist in the collection.
6 Public Boolean equals (Object O) Common Object comparison
7 public int hashcode () normal hash code
8 Public Boolean isempty () whether the common set is null
9 Public iterator <E> iterator () is instantiated by the iterator interface.
10 public Boolean remove (Object o) delete a specified object
11 Public Boolean removeall (collection <?> C) delete a group of Objects
12 public Boolean retainall (collection <?> C) normally Save the specified content
13. Public int size (): returns the size of the set.
14 public object [] toarray () converts a set to an object array.
15 Public <t> T [] toarray (T [] A) specifies the array type of the returned object.

Collection in EJB 2. X uses a large number of collection interfaces, but with the development, sun began to gradually standardize these standards, so in a sun Open Source-pet store, basically no longer directly use collection, use List or set to indicate the operation type more clearly.

Definition of collection sub-interface

Although the collection interface is the largest interface of the collection, If you directly use the collection interface for operations, the Operation meaning is not clear, therefore, the collection interface is not recommended in Java Development. The main sub-interface is as follows:

List interface: stores duplicate content
Set interface: duplicate content cannot be stored. All duplicate content is differentiated by hashcode () and equals.
Sortedset interface: sorts data in a set.
Queue interface (FIFO): Stack queue

Related Article

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.