Java Collection Class Rollup

Source: Internet
Author: User

I. Introduction to several important interfaces and classes

1. List (ordered, repeatable)
List of objects are ordered, but also can be repeated, list is concerned about the index, has a series of index-related methods, query fast. Since inserting or deleting data into the list collection is accompanied by the movement of the subsequent data, all insertions are slow to delete data.

2. Set (unordered, cannot repeat)
The objects stored in the set are unordered and cannot be duplicated, and the objects in the collection are not sorted in a particular way, simply by adding the object to the collection.

3. MAP (key value pair, key unique, value not unique)
The Map collection stores key-value pairs, keys cannot be duplicated, and values can be duplicated. According to the key to get the value, the map set to traverse the first get the set set of keys, the set set to traverse, to get the corresponding value.

Second, traverse

The following four common output methods are available in the class set:

1) Iterator: Iterative output, is the most used output mode.

2) Listiterator: is the sub-interface of the iterator, specifically used to output the contents of the list.

3) foreach output: A new feature provided after JDK1.5 that allows you to output an array or a collection.

4) for Loop

The code examples are as follows:

For the form: for (int i=0;i<arr.size (); i++) {...}

foreach form: for (int i:arr) {...}

form of Iterator: Iterator it = Arr.iterator ();
while (It.hasnext ()) {object o =it.next (); ...}

Iii. ArrayList and LinkedList

There is no difference in usage between ArrayList and LinkedList, but there are differences in function. LinkedList often used in the case of more additions and deletions and very few query operations, ArrayList is the opposite.

Iv. Collection of Maps

Implementation classes: HashMap, Hashtable, Linkedhashmap, and TreeMap

Java Collection Class Rollup

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.