java list contains string code example
Example 1: check if a list contains a string java
String search = "A";
for(String str: myList) {
if(str.trim().contains(search))
return true;
}
return false;
Example 2: java search arraylist
//create ArrayList
ArrayList<String> arrayList = new ArrayList<String>();
//add item to ArrayList
arrayList.add("item");
//check if ArrayList contains item (returns boolean)
System.out.println(arrayList.contains("item"));
//remove item from ArrayList
arrayList.remove("item");
Example 3: java arraylist contains string
boolean ans = arr.contains("geeks");