Java Collection: List, set, MAP, hashmap, hashtable, Vector

Source: Internet
Author: User
List, set, MAP, hashmap, hashtable, VectorCollection interface: In general development, the collection interface is usually not directly used to store data for clear purposes.

· Sub-interface: List

· Sub-interface: Set


Since list is an interface, you must use the subclass-> arraylist

If you want to use list, the format is: List L = new arraylist ();

 

★Difference between list and set:

1. List-element sequence, set-class set without repeated Elements

2. The basic usage of the set is the same as that of the list, but the hashset sub-classes are unordered during storage (Hash Storage)

3. Differences between element duplication and order:

· The data in the list can be retained by repeated elements.

· Duplicate elements are not allowed for data in the Set, and duplicate elements are replaced. // duplicate elements are overwritten, leaving only one

If hashset is used in a set, it is stored unordered by hash. If you want to store it in sequence, use the treeset subclass. Sort by comparable Interface

----------------------------------
★Map:


Save a pair of values (MAP ):

|-Hashmap: asynchronous processing, new class

|-Hashtable: synchronous processing, old class

|-Treemap: A set sorted by key


Elements are a collection of binary even pairs and cannot be repeated.

Each time you store a pair of values:Key-> Value


The main function of map is to use it as search, rather than as output. (Map for search data)

* Data Storage Method:

-Put (Object key, object value)

* Get content (based on the key ):

-Cobject get (Object key)


Objects of the map interface cannot be output directly using iterator.

To use iterator to output the content of the map interface object, follow these steps:
Map-> set-> iterator-> map. Entry-> key, values

----------------------------------
★Hashmap class

-The hashmap class uses a hash to implement the map interface.

-Hashmap is a ing Class (key-> value: Key-Value Pair)

----------------------------------
★Hashtable

-Similar to hashmap, but hashtable is synchronous

-Ing (key-> value: Key-Value Pair)

-Hashtable does not support iterative functions.

Properties class

-The properties class is a subclass of the hashtable class (hashtable <-properties)

-List of values to be kept

------------------
☆Property class-Properties

(Properties-> string; hashtable-> Object)


Unlike hashtable, the properties class stores strings while hashtable stores objects.

-Setproperty (string key, string value)

-Getproperty (string key)

----------------------------------
★Treemap class(Sort by key)

-The treemap class can sort data.

-Quick Search

----------------------------------
★Vector

|-List: Repeated elements are allowed.

|-Arraylist: asynchronous processing. The new class can only be output using iterator.

|-Vector: synchronous processing. The old class can be output simultaneously with iterator and enumeration.


Neither list nor set can use enumeration output.

Another subclass of list: vector can use enumeration to output


Vector

-Implement Dynamic Array Using Vector

-The vector is synchronized.

----------------------------------

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.