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

Class Main

FirstRepeatedWords.java:2–28  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1import java.util.*;
2public class Main
3{
4 public static void main(String args[])
5 {
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

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected