Jen Baby Java basic Notes collection framework

Source: Internet
Author: User

Basic interface: Collection
Interface: List
Implementation class: ArrayList LinkedList
Interface: Set (unique, unordered)
Implementation class: HashSet (hash) TreeSet
Map Interface: Map
Implementation class: HashMap
----------------------------------------------------------------------
ArrayList class
Features: variable length, continuous space, any type, same type
Applicable: Suitable for multiple traversal of the collection
Method:
Boolean Add (Object o) adds an element at the end of the collection
void Add (int index,object o) adds an element at the specified position
int size () returns the number of elements in the collection
Object get (int index) returns the collection element based on position
---------------------------------------------------------------------------
LinkedList class
Features: Linked list form
Usage: High efficiency of INSERT and delete
Method:
void AddFirst (); Add an element to the header of the collection
void AddLast (); Add an element at the end of the collection
Object GetFirst (); Gets the first element
Object GetLast (); Gets the last element
Object Removefirst (); Remove and return the first element
Object Removelast (); Remove and return the last element
--------------------------------------------------------------------------------
HashSet class
Features: Unique, unordered, can store null
Usage: Use of conditions that do not know the data index
Method:
Boolean Add (Object o) If no element is specified in this set, the element is added to the collection
-------------------------------------------------------------------------------
Iterator Interface (iterator)
Features: Implement various collection traversal operations
Get method: Use the Collection class object to call the iterator () method to return the iterator object
Iterator It=list.iterator ();
Method:
Boolean Hasnext () determines whether the next accessible element exists, if any, true
Object Next () returns the next element to be accessed
-------------------------------------------------------------------------------
HashMap class
Feature: Stores a pair of key (key) value objects, key does not allow duplicates
Applicable: When there is a correspondence between the time can be used
Method:
Object put (object Key,object value) puts key with value in the collection
Object get (Object key) Gets the value associated with key
Set KeySet () Gets the collection of all keys
Collection values () gets a collection of all value
Boolean ContainsKey (Object key) to determine if a key exists in the collection
Boolean Containsvalue (Object value) to determine whether the value exists in the collection
--------------------------------------------------------------------------------
Collections Operation Class
Features: The collection can be sorted, found and replaced, and so on.
Collections.sort (set); Sort Ascending
Collections.binarysearch (set, an element within a set); Element Lookup
Collections.fill (set, new element to replace); Replace element
-------------------------------------------------------------------------
Generic type
Syntax: Collection type < actual type > Collection Object =new collection type < actual type > ();
Note the point:
1. When using the List.get () method, the object type is returned, and the type is forced to be converted to the corresponding data type
The Get () method is not present on the 2.Set interface

Jen Baby Java basic Notes 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.