(String str)
| 6 | firstRepeatedWord("shashwat had been saying that he had been coding"); |
| 7 | } |
| 8 | public static void firstRepeatedWord(String str) |
| 9 | { |
| 10 | HashSet<String> set = new HashSet<>(); |
| 11 | if(str.length()==0) |
| 12 | { |
| 13 | System.out.println("Not Found!"); |
| 14 | return; |
| 15 | } |
| 16 | String words[] = str.split(" "); |
| 17 | for(String s : words) |
| 18 | { |
| 19 | if(set.contains(s)) |
| 20 | { |
| 21 | System.out.println("First repeated is: "+s); |
| 22 | return; |
| 23 | } |
| 24 | set.add(s); |
| 25 | } |
| 26 | System.out.println("Not Found"); |
| 27 | } |
| 28 | } |