java - Checking if a string contains any of the strings in an array -
without () loops such as
for(int j =0; j < array.length; j++) { }
i want able check if string contains of strings in array globally. for() loops don't work.
i have tried
int arraylength; while(arraylength < array.length()){ arraylength++; } if(string.contains(array[arraylength]) {}
but returns error.
edit:
to clear up:
i want like
if (string.contains(**code checks strings in array**)
so can check if string contains of strings in array. have mentioned, loops not work because want able execute line of code above anywhere in class.
you can this:
string veryhugestring = ....;// string[] words = new string[]{...}; boolean foundatleastone = false; (string word : words) { if (veryhugestring.indexof(word) > 0) { foundatleastone = true; system.out.println("word: " + word + " found); break; } } system.out.println("found @ least 1 : " + foundatleastone);
Comments
Post a Comment