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

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -