final HashSet<String> VALUES = new HashSet<String>(Arrays.asList(new String[] {"OK (0.07, 0.05, 0.01)",
"OK (0.07, 0.05, 0.02)",
"OK (0.07, 0.05, 0.03)",
"OK (0.07, 0.05, 0.04)"}));
String s="OK";
System.out.println(VALUES.contains(s));
Gives me false. How do I check if "OK" exists in each of the elements?
Currently, you're checking if your Set contains the value OK. If you want to check if each of the elements of the Set contains OK (note the difference), you'll need to loop through the values of your Set like the others stated.
Using java-8 and streams, you can also do :
boolean b = VALUES.stream().allMatch(s -> s.contains("OK"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With