Try use lambdaj (download here,website) and hamcrest (download here,website), this libraries are very powerfull for managing collections, the following code is very simple and works perfectly:
import static ch.lambdaj.Lambda.having;
import static ch.lambdaj.Lambda.on;
import static ch.lambdaj.Lambda.select;
import static org.hamcrest.Matchers.containsString;
import java.util.Arrays;
import java.util.List;
public class Test2 {
public static void main(String[] args) {
List<String> list = Arrays.asList("A","BB","DCA","D","x");
String strTofind = "C";
System.out.println("List: " + list.toString());
boolean match = select(list, having(on(String.class), containsString(strTofind))).size()>0;
System.out.println("The string " + strTofind + (!match?" not":"") + " exists");
strTofind = "X";
match = select(list, having(on(String.class), containsString(strTofind))).size()>0;
System.out.println("The string " + strTofind + (!match?" not":"") + " exists");
}
}
This shows:
List: [A, BB, DCA, D, x]
The string C exists
The string X not exists
Basically, in one line you can search the string is in any strinf of the array:
boolean match = select(list, having(on(String.class), containsString(strTofind))).size()>0;
With this libraries you can solve your problem in one line. You must add to your project: hamcrest-all-1.3.jar and lambdaj-2.4.jar Hope this will be useful.
Note: in my example i use a List then if you want use an array: Arrays.asList(array)
(array is string[])