MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / firstRepeatedWord

Method firstRepeatedWord

FirstRepeatedWords.java:8–27  ·  view source on GitHub ↗
(String str)

Source from the content-addressed store, hash-verified

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}

Callers 1

mainMethod · 0.95

Calls 1

addMethod · 0.45

Tested by

no test coverage detected