Source Code : Search an element of Java ArrayList
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Search an element of Java ArrayList
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
ArrayList<String> arrayList = new ArrayList<String>();
arrayList.add("2");
arrayList.add("2");
arrayList.add("3");
arrayList.add("4");
arrayList.add("5");
arrayList.add("1");
arrayList.add("2");
System.out.println(arrayList.contains("2"));
int index = arrayList.indexOf("4");
if (index == -1)
System.out.println("not contain 4");
else
System.out.println("4 at index :" + index);
int lastIndex = arrayList.lastIndexOf("1");
if (lastIndex == -1)
System.out.println("not contain 1");
else
System.out.println("Last index :"+ lastIndex);
}
}
/*true
4 at index :3
Last index :5
*/
Thank with us