I have a String[]
with values like so:
public static final String[] VALUES = new String[] {"AB","BC","CD","AE"};
Given String s
, is there a good way of testing whether VALUES
contains s
?
arraysjava
I have a String[]
with values like so:
public static final String[] VALUES = new String[] {"AB","BC","CD","AE"};
Given String s
, is there a good way of testing whether VALUES
contains s
?
Best Answer
Warning: this doesn't work for arrays of primitives (see the comments).
Since java-8 you can now use Streams.
To check whether an array of
int
,double
orlong
contains a value useIntStream
,DoubleStream
orLongStream
respectively.Example