I want check whether a String value val
is contained within a List of Strings lets call it stringList.
I am doing this
if(stringList.con
That doesn’t sound right: contains
uses equals
rather than ==
, so if the string is in the list, it should be found. This can be verified in the indexOf
method of the superclass AbstractList used by ArrayList
.
Following your edit, make sure you trim
strings before doing contains
, as otherwise they may contain the newline
character(s).