Skip to content

Commit 5d2dfd2

Browse files
Merge pull request #159 from Rishabh2257/patch-1
Duplicate
2 parents 966ae8c + 7c7be7a commit 5d2dfd2

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

duplicate

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import java.util.HashMap;
2+
import java.util.Map;
3+
import java.util.Set;
4+
public class Details {
5+
public void countDupChars(String str){
6+
7+
8+
Map<Character, Integer> map = new HashMap<Character, Integer>();
9+
10+
char[] chars = str.toCharArray();
11+
12+
13+
for(Character ch:chars){
14+
if(map.containsKey(ch)){
15+
map.put(ch, map.get(ch)+1);
16+
} else {
17+
map.put(ch, 1);
18+
}
19+
}
20+
21+
22+
Set<Character> keys = map.keySet();
23+
24+
for(Character ch:keys){
25+
if(map.get(ch) > 1){
26+
System.out.println("Char "+ch+" "+map.get(ch));
27+
}
28+
}
29+
}
30+
31+
public static void main(String a[]){
32+
Details obj = new Details();
33+
System.out.println("String: BeginnersBook.com");
34+
System.out.println("-------------------------");
35+
obj.countDupChars("BeginnersBook.com");
36+
37+
System.out.println("\nString: ChaitanyaSingh");
38+
System.out.println("-------------------------");
39+
obj.countDupChars("ChaitanyaSingh");
40+
41+
System.out.println("\nString: #@$@!#$%!!%@");
42+
System.out.println("-------------------------");
43+
obj.countDupChars("#@$@!#$%!!%@");
44+
}
45+
}

0 commit comments

Comments
 (0)