class class16{
private static void gett(String s)
{
Map<Character,Integer> map = new HashMap<Character,Integer>();
for(char c:s.toCharArray())
{
if(map.containsKey(c))
{
int temp = map.get(c);
temp++;
map.put(c, temp);
}
else
{
map.put(c, 1);
}
}
Set<Entry<Character,Integer>> set = map.entrySet();
Iterator<Entry<Character, Integer>> it = set.iterator();
while(it.hasNext())
{
Entry<Character,Integer> entry = (Entry<Character, Integer>) it.next();
System.out.print(entry.getKey()+"("+entry.getValue()+")");
}
}
public static void main(String... args){
gett("abcdekka27qoq");
}
} |