Three large sets of frameworks in Java

Source: Internet
Author: User
Tags addall set set

First, List collection

1, list implementation of the super-parent interface: Collection

Stores an ordered set of objects that are not unique (allow duplicates).

2, understand the ArrayList class

A): Defined format:arraylist< specific type > Set name = new arraylist< specific type > ();

B): How the data is stored: underlying or array storage

C): The type of the object: In the list collection, if you define the collection object without defining the type of the object, it indicates what type of object can be stored directly in the list collection, and if you want to use the elements inside, you need to use instanceof to determine the type of the element. Format: The type that the element instanceof; returns TRUE or false. Follow-up needs strong turn.

D): Collection design: Generic way to type specified,arraylist< concrete type >

Features: Orderly, repeatable, variable-sized containers

Traverse: For Loop

E): basic operation:

Added: Collection name. Add (Element); Add at the end of the collection,

Collection name. Add (number, Element); Load the specified location

The collection name. AddAll (another set name); Add to the last

Collection name. AddAll (number, another set name); Load specified location

Delete: The collection name. Remove (number); Remove an element from a specified position

The collection name. Remove (Element); Removes the first occurrence of the specified element in the collection (if one exists)

The collection name. RemoveAll (another set name); Remove all elements from another collection

The collection name. Retaintall (another set name); Keep all elements in the other collection only

The collection name. Clear (); Emptying the collection

Judge/Get: Collection name. get (number); Gets the element at the specified position

The collection name. Contains (element); Returns True if the collection contains the element.

The collection name. Contains (another set name); Determines whether to include all elements of another collection

The collection name. IndexOf (Element); Returns the index of the element, none returns-1

The collection name. Equals (Element); Determines whether the element returns TRUE or false consistent with the elements of the collection

Change: Set name. Set (number, Element); Replaces the element at the specified position with this element

Other: Set name. Size (); Gets the size of the collection

Second, set set

1, set implementation of the super-parent interface: Collection

2, understand the HashSet class

A): Defined format: hashset< specific type > Set name = hashset< specific type > ();

B): Data storage: Follow the hash algorithm to store data

C): Type of object: The collection object type must be defined, otherwise it will affect subsequent use

D): Collection design: Generic way to type specified:hashset< concrete type >

Features: Elements unordered, non-repeatable, variable-sized containers

Note: The underlying is not really disorderly, follow the hash algorithm to ensure the storage of data, but as a user, we understand the disorder

Traversal: You need to use the iterator:iterator< type > name = collection name. Iterator ();

E): basic operation:

Added: Collection name. Add (Element); Adds the specified element (but contains the previous collection)

Delete: The collection name. Remove (Element); Remove the specified element

The collection name. Clear (); Emptying the collection

Judgment: Set name. containts (Element); Returns True if the collection contains this element

Other: Set name. Size (); Get the size of the collection

iterator< Type > Name = collection name. Iterator (); Traversal for the collection

Third, Map collection

1, map does not implement the super-parent interface, not the direct interface subclass of collection

2, understand the HashMap class

A): Defined format:hashmap< type, type > Set name = new hashmap< type, type > ();

B): How data is stored: How key+value is stored

C): Type of object: The collection object type must be defined, otherwise it will affect subsequent use

D) Design of the collection: generic way to type the specified:hashmap< specific type >

Features: A piece of data, consisting of two parts: key and value, element unordered, non-repeatable, variable size container

Traversal: An iterator that needs to use a key set< type > Name 1 = collection name. KeySet ();

iterator< type > name = Name 1.iterator ();

E): basic operation

Add: Set name. Put (key, value); Associates the specified value with the specified key (is put, not add) in this mapping

Delete: The collection name. Remove (key); Removes the mapping of the specified key from the map (if present)

Judgment: Set name. ContainsKey (key); Returns TRUE if this map contains a mapping relationship for the specified key

Collection name. Containsvalue (value); Returns true if this mapping maps one or more keys to the specified value

Other: Set name. Size (); Get the size of the collection

Note: In the Map collection, a key can only correspond to a value, but a value can have multiple keys corresponding, if put (put) a same key to map, then the new element will replace the original element, will replace the elements returned, you can receive, and do the subsequent processing

Three large sets of frameworks in Java

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.