[Solved] Trouble with finding a substring in a string [closed]
Set<String> words = new HashSet<>(); String str = “Java Ruby PHP. Java is good. PHP please looks at Java”; Matcher mat = Pattern.compile(“\\b(\\w+)(?=\\b.*\\1)”).matcher(str); while(mat.find()){ words.add(mat.group(1)); } System.out.println(words); Also you can just split string by words and calculate count using Map. And then filter words with count > 1. 1 solved Trouble with finding a substring … Read more