Join
Blogs
Questions
Videos
Tags
Members
Search
 
 
Create your own blog, earn points and get popular!

Search elements in Java ArrayList using indexOf, lastIndexOf, size and contains methods

Methods to Search elements within Java ArrayList

Java ArrayList provides following methods to search a particular element within the ArrayList.

1) int indexOf(Object element)

Search for a particular element in the ArrayList and return the position of the first occurrence of the element if found within the list, otherwise returns -1.

2) intLastIndexOf(Object element)

Search for a particular element in the ArrayList and return the position of the last occurrence of the element if found within the list, otherwise returns -1.

3) int size()

Returns the number of elements contained in the list.

4) boolean isEmpty()

Returns true of the list is empty, otherwise returns false.

5) boolean contains(Object element)

Returns true if the specified element is found in the list, otherwise returns false.


<< Add Elements to Java ArrayList    Remove, Replace, Search Elements from Java ArrayList >>
Your rating: None Average: 2.7 (3 votes)
Share this

Post new comment