Check to see if an ArrayList contains a given item in Java
Description
The following code shows how to check to see if an ArrayList contains a given item.
Example
/*from w w w.j av a 2 s . c om*/
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
List list = new ArrayList();
list.add("Item 1");
list.add("Item 2");
if (list.contains("Item 1")) {
System.out.println("True");
} else {
System.out.println("False");
}
}
}
The code above generates the following result.