Friday, March 4, 2011

How do I know if an ArrayList contains a specified item?


/**---------------------------------------------------------*
* @author Madarapu Naveen *
* http://madarapunaveen.blogspot.com *
* ---------------------------------------------------------*
*/


import java.util.ArrayList;
import java.util.List;

public class ArrayListContains {
public static void main(String[] args) {
ArrayList 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");
}
}
}

No comments:

Post a Comment