File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments