Traditionally, you can develop your own logic to compare strings stored in an ArrayList . There are several ways to do this, as shown below.
public boolean containsCaseInsensitive(String strToCompare, ArrayList<String>list) { for(String str:list) { if(str.equalsIgnoreCase(strToCompare)) { return(true); } } return(false); }
Why you should not use some direct and convenient methods, for example, SortedSet, as shown below with a case-insensitive comparator .
Set<String> a = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER); a.add("A"); a.add("B"); a.add("C"); Set<String> b = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER); b.add("a"); b.add("b"); b.add("c"); System.out.println(b.equals(a));
Will compare two different sets, ignoring case and return true , in this particular situation, and your comparison will work without any problems.
Lion Jan 06 2018-12-12T00: 00Z
source share