Java series Learning (14th)-set, java series set

Source: Internet
Author: User

Java series Learning (14th)-set, java series set

1. Set learning in java

2. Common Methods in Collection

   

1. Add features

BooleanAdd(E): Add an element.

BooleanAddAll(Collection <? Extends E> c): Add a set.

2. Deletion

VoidClear(): Removes all elements.

BooleanRemove(Object o): removes a specified element.

BooleanRemoveAll(Collection <?> C): remove the elements from the specified set. [true is returned if any element is removed]

3. Judgment

BooleanContains(Object o): determines whether the set contains the specified element.

BooleanContainsAll(Collection <?> C): determines whether the set contains the specified set element. [true is returned only if all elements are included]

BooleanIsEmpty(): Determines whether the set is empty.

BooleanEquals(Object o)

4. Obtain Functions

Iterator <E>Iterator(): [Methods inherited from the parent class]

IntHashCode(): Returns the hash value of the set.

5. Length Function

IntSize(): Gets the number of elements in the set.

6. Intersection Function

BooleanRetainAll(Collection <?> C): intersection of two sets [A does intersection on B, and the result is saved in A; true is returned only when A remains unchanged]

7. Convert the set into an array

Object []ToArray(): Converts a set into an array to traverse the set.

<T> T []ToArray(T [] ):

3. List-specific methods

   

1. Add features

VoidAdd(Int index, E element): Add an element at a specified position

BooleanAddAll(Int index, Collection <? Extends E> c): Add a set at a specified position.

2. Obtain Functions

EGet(Int index): gets the elements at the specified position [traversal can be achieved by combining with size]

List <E>SubList(Int fromIndex, int toIndex)

IntIndexOf(Object o)

IntLastIndexOf(Object o)

3. List iterator

ListIterator <E>ListIterator(): List set unique iterator

ListIterator <E>ListIterator(Int index)

4. Deletion

ERemove(Int index): deletes an element based on the index and returns the deleted element.

5. Modify Functions

ESet(Int index, E element): modifies an element based on the index and returns the modified element.

4. unique functions of Vector

   

1. Add features

Public voidAddElement(E obj)

Public voidInsertElementAt(E obj, int index)

2. Obtain Functions

Public EElementAt(Int index)

Public Enumeration <E>Elements()

Public intCapacity(): Get the capacity of the Set

Public intIndexOf(Object o, int index)

Public intLastIndexOf(Object o, int index)

Public EFirstElement(): Gets the first element of the set.

Public ELastElement(): Gets the last element of the set.

3. Replication

Public voidCopyInto(Object [] anArray)

4. Modify Functions

Public voidEnsureCapacity(Int minCapacity): increases the capacity of the set.

Public voidSetElementAt(E obj, int index)

Public voidTrimToSize(): Make the set equal to the current size

Public voidSetSize(Int newSize): set the size of the set.

5. Removal

Public voidRemoveAllElements(): Remove all elements and set the size to zero.

Public booleanRemoveElement(Object obj): removes the first element.

Public voidRemoveElementAt(Int index): removes a specified element.

Protected voidRemoveRange(Int fromIndex, int toIndex): removes the specified range element (including fromindex, excluding toIndex]

6. Formatting

Public StringToString(): Return the string form of the set [view the source code, rewrite]

The unique method of listing:(Custom stack can be implemented)

Public classRevoke list <E>Extends AbstractSequentialList <E> implements List <E>, Deque <E>, Cloneable, Serializable

   

1. Add features

Public voidAddFirst(E)

Public voidAddLast(E)

2. Obtain Functions

3. public EGetLast()

4 public EGetLast()

3. Deletion

Public ERemoveFirst()

Public ERemoveLast()

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.