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

Popular posts from this blog

maven fortify plugin : Unable to load build session with ID XXXXX .. See log file for more details -

c# - Primavera WebServices does not return any data -

android - Display emoji panel with genymotion - keyboard/touch input? -