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.
|