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

Class DuplicateCount

DuplicateCount.java:2–20  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1import java.util.*;
2class DuplicateCount{
3 public static void main(String args[])
4 {
5 String s = "SHASHWAT";
6 countDuplicates(s);
7 }
8 public static void countDuplicates(String inp)
9 {
10 HashMap<Character,Integer> map = new HashMap<>();
11 for(int i=0;i<inp.length();i++)
12 {
13 map.put(inp.charAt(i),map.getOrDefault(inp.charAt(i),0)+1);
14 }
15 for(Map.Entry<Character,Integer> e : map.entrySet())
16 {
17 System.out.println(e.getKey() + ":" + e.getValue());
18 }
19 }
20}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected