I am reading a user input. I was wondering how I would apply equalsIgnoreCase to the user input?
ArrayList<String> aListColors = new ArrayList<String>();
aListColors.add("Red");
aListColors.add("Green");
aListColors.add("Blue");
InputStreamReader istream = new InputStreamReader(System.in) ;
BufferedReader bufRead = new BufferedReader(istream) ;
String rem = bufRead.readLine(); // the user can enter 'red' instead of 'Red'
aListColors.remove(rem); //equalsIgnoreCase or other procedure to match and remove.
If you don’t need a
Listyou could use aSetinitialized with a case-insensitive comparator:Now when you call remove, the case of the argument no longer matters. So both of the following lines would work:
or
But this will only work if you don’t need the ordering that the
Listinterfaces gives you.