Java Collection Framework

Source: Internet
Author: User

A comparison of sets and arrays

  Using an array to store objects has some drawbacks, and the Java collection is like a container that dynamically puts references to multiple objects in a container.

The disadvantage of an array: Once the length is set, it cannot be changed, and the number of elements in the array is unknown.

Ii. Overview of the collection

  |--- Collection Collection

|---List interface: ordered, repeatable sequence.

|---ArrayList collection (the main manifestation of list)

|---linkedlist

|---Vector

|---Set interface: unordered, non-repeatable.

|---TreeSet

|---HashSet

|---Map collection: Key-->value Key-value pairs

Iii. Common methods of collection

 1.size (): Returns the number of collection elements  2.add (): Adds a new element to the collection /span>3.addall (): Copies the elements in the parameter collection to the current collection  4 5 6, Contains (Object obj): Determines whether the collection contains the obj element  7 8, Retainall (): Takes the intersection of the current collection and the parameter collection, and leaves it to the current collection  9, Remove (Object obj): Deletes the first occurrence of obj in the current collection,  10 11 12, ToArray (): Converts the current combination into an array  13 14, iterator (): Returns an object of the iterator interface implementation class. 
Collection Common Methods list

  Note: You must override the Equals () method if you are comparing objects for equality when you add custom types to the collection.

Iv. Traversal of a collection

  (1) for (int)

(2) Enhanced for ()

(3) iterator Iterator,hasnext (), Next ().

V. List

  Features: Ordered and repeatable code.

Common methods:

(1) void Add (int index,object obj);

(2) Boolean addall (int index,collection coll);

(3) Object get (int index);

(4) int indexOf (Object obj);

(5) int lastof (Object obj);

(6) Object Remove (int index);

(7) Object set (int index,object obj);

(8) List sublist (int fromindex,int toindex);

Vi. Collection Frame Structure

  The picture is slightly ugly ah, hahaha, today for everyone to update the contents of the collection, if you feel that it helps, please order to praise it!!!

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.