Summary of Java Collection Operations essence

Source: Internet
Author: User

A. Set
1.HashSet
Boolean Add (E) adds
Access
Boolean remove (E) Delete
Iterator<e> Iterator Traversal
int size ()

Boolean isEmpty () is empty
Whether the Boolean contains (Object O) contains
void Clear () empty (delete all elements)

Object[] ToArray ()
<T> t[] ToArray (t[] a)

2.LinkedHashSet
Boolean Add (E) adds
Access
Boolean remove (E) Delete
Iterator<e> Iterator Traversal
int size ()

Boolean isEmpty () is empty
Whether the Boolean contains (Object O) contains
void Clear () empty (delete all elements)

3.TreeSet
Boolean Add (E) adds
Access
Boolean remove (E) Delete
Iterator<e> Iterator Traversal
int size ()

Boolean isEmpty () is empty
Whether the Boolean contains (Object O) contains
void Clear () empty (delete all elements)

comparator<? Super E> Comparator () returns the comparer that is used to sort the elements in the collection, or null if this collection uses the natural ordering of its elements.
E First () returns the current (lowest) element in the collection
E last ()
E Pollfirst () retrieves and deletes the first (lowest) element, or returns NULL if the collection is empty.
E Polllast ()
e Lower (e e) returns the largest element in the collection that is strictly less than the given element, or null if no such element is in the set.

Two. List
1.ArrayList
Boolean Add (e e) void add (int index,e Element) added
E get (int index) access
int indexOf (Object o) returns the index of the first occurrence of the specified element
Boolean remove (int index)
Boolean remove (Object o)

Iterator<e> Iterator ()
Listiterator<e> Listiterator ()
listiterator<e> listiterator (int index) traversal
int size ()
Boolean isEmpty () is empty
Whether the Boolean contains (Object O) contains
void Clear () empty (delete all elements)
Object[] ToArray ()
<T> t[] ToArray (t[] a)
2.Stack
E push (e Item) presses into stack
E Peek () View the cashing at the top of the stack without removing
E pop () removes the top object and returns
Boolean empty () is empty
int search (object o) returns the position of the object in the stack, with a base of 1
3.LinkedList

Add to:
Public boolean Add (Object Element): The element will be added to the end of the list;
public boolean Add (int index, Object Element): The element will be added to the list at the specified index (starting at 0);
public boolean AddFirst (Object Element): inserted in the head;
public boolean addlast (Object Element): inserted at the tail;
Access:
E GetFirst ()
E GetLast ()
E get ()----No
Delete:
Remove (): Deletes the first element;
Remove (int index): Deletes the element at the specified index position (starting at 0);
Removefirst (): Delete the first element;
Removelast (): Delete the last element;
Clear (): Clears the list;
List.sublist (1,3). Clear (): Deletes list elements by range;


Whether Boolean contains () contains
void set (int index,element) Replace element
int indexOf () find element position

Implementation stack:
void AddFirst (T v)-----push
T GetFirst ()-----------Peek
T Removefirst ()--------Pop
Boolean isEmpty ()------Empty
String toString ()------Print stack Element

Implementation queue;
Private queue<t> storage = newlinkedlist<t> ();
void Offer (T v)-------insert end of Team
T Peek ()--------------get the team head but do not remove
T element ()-----------The only difference between this method and the Peek method is that if this queue is empty, it throws an exception
T poll ()--------------get to the opponent and remove
T Remove ()------------This method differs from the poll method in that if this queue is empty, it throws an exception
Boolean isEmpty ()------Whether the queue is empty
String toString ()------print queue Element
Three. Queue
1.PriorityQueue
Boolean Add (E E)
Boolean offer (e e)-----add
E-Peek ()
E poll ()---------------get to the opponent
Boolean remove (Object o)---Delete
int size ()-------------sizes
iterator<e> Iterator ()---traversal

Whether the Boolean contains (Object o)----contains
comparator<? Super E> Comparator ()----Returns the comparer used to sort the elements in this queue, or null if the queue is sorted based on the natural ordering of its elements
Object[] ToArray ()
<T> t[] ToArray (t[] a)

Four. Map
V Put (K key, V value)------added
V get (Object key)----------Access
Remove (Object key)---------Delete
Traverse:
EntrySet ()------Get key value pairs
KeySet ()--------Get the key
VALUES ()--------Get value

int size ()-------sizes
Boolean isEmpty ()---is empty



Summary of Java Collection Operations essence

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.