Several arraylist operations

Source: Internet
Author: User

1. Delete the arraylist set Element

When deleting elements in the arraylist set, the clear, remove, rmoveat, and removerange methods are provided.

The clear method removes all elements.

Ref: int [] arr = new int [] {1, 2, 3, 4, 5, 6 };

Arraylist list = new arraylist (ARR );

List. Clear ();

2. Remove Method

This method is used to remove a specific object from the arraylistFirst match

Ref: int arr = new int [] {1, 2, 3, 4, 5, 6 };

Arraylist list = new arraylist (ARR );

List. Remove (3 );

3. removeat Method

Used to remove the elements of the specified index in the arraylist.

Ref:

Int arr = new int [] {1, 2, 3, 4, 5, 6 };

Arraylist list = new arraylist (ARR );

List. removeat (3 );

4. removerange Method

This method is used to remove a certain range of elements from the arraylist.

Ref: int [] arr = new int [] {1, 2, 3, 4, 5, 6 };

Arraylist list = new arraylist (ARR );

List. removerange (3, 2 );

Search for arraylist set Elements

You can use the contain method, indexof method, and lastindexof method provided by the arraylist class.

1. contian Method

Used to determine whether an element is in the arraylist set.

2. indexof Method

Returns the index of the first matching item in the entire arraylist starting from scratch.

3. lastindexof Method

Returns the index of the last matching item in the entire arraylist starting from scratch.

 

Several arraylist operations

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.