Java Collection Framework

Source: Internet
Author: User

The Collection interface stores a set of objects that are not unique (allow duplicates) and are unordered.

The set interface inherits the Collection interface, storing a unique set of objects that are not allowed to be duplicated or unordered.

The List interface inherits the Collection interface, which stores a set of objects that are not unique (allowing duplicates), ordered (placed in the order in which elements are inserted, and not rearranged).

The implementation of the list interface has two common implementation classes one is ArrayList and linkedlist. They can all accommodate all types of objects, including null, allow repetition, and guarantee the order in which elements are stored

The ArrayList array is encapsulated and the variable-length arrays are implemented. ArrayList stores data in the same way and in the same array, allocating contiguous space in memory. The advantage of this is that it is more efficient to traverse elements and elements randomly to access elements.

The LinkedList uses the list storage method. High efficiency when inserting and deleting elements.

The map interface stores a pair of key-value objects that provide a mapping of the key (key) to value. The key in the map does not require ordering and does not allow duplication. Value also does not require ordering, but allows repetition.

The lterator interface is the interface responsible for defining access and traversal elements.

Common methods:

Collection interface

Add (), remove (), iterator (), size (), clear (), contains (), IsEmpty ()

ArrayList class

Get ()

LinkedList class

AddFirst (), AddLast (), Removefirst (), Removelast (), GetFirst (), GetLast ()

HashSet class

ADD (), remove (), clear (),

HashMap class

Put (key, value), remove (key), get (key), KeySet (), ContainsKey (), Containsvalue ()

Iterator Interface (iterator)

Hasnext (), Next ()

Java Collection Framework

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.