I have a String[]
with values like so:
public static final String[] VALUES = new String[] {\"AB\",\"BC\",\"CD\",\"AE\"};
Given
the use of a Spliterator
prevents the unnecessary generation of a List
boolean found = false; // class variable
String search = "AB";
Spliterator spl = Arrays.spliterator( VALUES, 0, VALUES.length );
while( (! found) && spl.tryAdvance(o -> found = o.equals( search )) );
found == true
if search
is contained in the array
this does work for arrays of primitives
public static final int[] VALUES = new int[] {1, 2, 3, 4};
boolean found = false; // class variable
int search = 2;
Spliterator spl = Arrays.spliterator( VALUES, 0, VALUES.length );
…