How to determine if one line contains one of several characters in another line:
If you want a quick solution:
public static void main(String[] args) { System.out.println(containsChars("sadsdd$sss^dee~", "$^~")); } public static boolean containsChars(String str, String chars) { for (int i = 0; i < chars.length(); i++) { char c = chars.charAt(i); for (int j = 0; j < str.length(); j++) { if (c == str.charAt(j)) { return true; } } } return false; }
Of course, not as small or elegant as a regular expression, but it is fast.
source share