import java.util.*;
class MapTree
{
public static void main(String[] args)
{
String s=CharCount("a.a5bcab");
System.out.println(s);
}
public static String CharCount(String str)
{
int count=0;
char[] chs=str.toCharArray();
TreeMap<Character,Integer> tm=new TreeMap<Character,Integer>();
for(int x=0;x<chs.length;x++)
{
if(!(chs[x]>='a'&& chs[x]<='z' ||chs[x]>='A'&& chs[x]<='Z'))
continue;
Integer value=tm.get(chs[x]);
if(value!=null)
count=value;
count++;
tm.put(chs[x],count);
count=0;
/*
if(value==null)
tm.put(chs[x],1);
else
{
value=value+1;
tm.put(chs[x],value);
}
*/
}
//System.out.println(tm);
StringBuilder ab=new StringBuilder();
Set<Map.Entry<Character,Integer>> entry=tm.entrySet();
Iterator<Map.Entry<Character,Integer>> it=entry.iterator();
while(it.hasNext())
{
Map.Entry<Character,Integer> me=it.next();
Character ch=me.getKey();
Integer value=me.getValue();
ab.append(ch+"("+value+")");
}
return ab.toString();
}
}
|