java - Trouble with finding a substring in a string -
java - Trouble with finding a substring in a string -
i need print words appear more 1 time in string.
example
input:s = "java ruby php. java good. php please looks @ java"
output:
java php
set<string> words = new hashset<>(); string str = "java ruby php. java good. php please looks @ java"; matcher mat = pattern.compile("\\b(\\w+)(?=\\b.*\\1)").matcher(str); while(mat.find()){ words.add(mat.group(1)); } system.out.println(words);
also can split string words , calculate count using map. , filter words count > 1.
java string
Comments
Post a Comment