Java, return if trimmed String in List contains String
You need to iterate your list and call String#trim
for searching:
String search = "A";
for(String str: myList) {
if(str.trim().contains(search))
return true;
}
return false;
OR if you want to perform ignore case search, then use:
search = search.toLowerCase(); // outside loop
// inside the loop
if(str.trim().toLowerCase().contains(search))
With Java 8 Stream API:
List<String> myList = Arrays.asList(" A", "B ", " C ");
return myList.stream().anyMatch(str -> str.trim().equals("B"));