Find out if a String contain a value in an array in Java -
Is there a way to find out if there is any value in your string string []? This is my code: string s = "hello world! My name is bao" ;; String [] arr = new string [] {"o", "!", "-", "y", "z"}; (String item: arr) {if (s.contains (item)) {System.out.println ("string contains:" + item); } Else {System.out.println ("Not included in the string:" + item); }} Is there a way to do this? I do not want to use the for loop for this. It may slow down when the array contains 4000+ strings. For large arrays of strings, first it is to assign an array and target string to a HashSet . Duplicate characters will be removed from being a set , and compared with having the hash version will be faster. After that you can do some work of quick set subtraction to get your answer: string s = "hello world! My name is bao" ;; String [] arr = new string [] {"o", "!", "-...