Monday 16 October 2017

Java - search a string in string array

itemprop="text">



In java do we
have any method to find that a particular string is part of string array.
I
can do in a loop which I would like to
avoid.



e.g.



String
[] array = {"AA","BB","CC" };

string x =
"BB"


I would like a



if (some condition to tell
whether x is part of array) {
do something
} else {
do
soemthing
}



Answer




Do something
like:



Arrays.asList(array).contains(x);


since
that return true if the String x is present in the array (now converted into a
list...)






if(Arrays.asList(array).contains(x)){

// is present ... :)
}


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...