I have an ArrayList();
List<String> list = new ArrayList<>();
list.add("aaa");
list.add("BBB");
list.add("cCc");
System.out.println(list.contains("aAa"));
Here i want to check contains() method with equalsIgnoreCase method in same line. How can i do it?
boolean containsEqualsIgnoreCase(Collection<String> c, String s) {
for (String str : c) {
if (s.equalsIgnoreCase(str)) {
return true;
}
}
return false;
}
You can't. The contract of contains
is that it defers to equals
. That's a fundamental part of the Collection
interface. You have to write a custom method that iterates through the list and checks each value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With