import
java.util.Iterator;
import
java.util.Set;
import
java.util.TreeMap;
public
class
TreeMapDemo
{
public
static
void
main(String[] args)
{
System.out.println(
"脚本之家测试结果:"
);
String s =
"aagfagdlkerjgavpofjmvglk我是你的"
;
method(s);
}
private
static
void
method(String s)
{
TreeMap<Character,Integer> tm =
new
TreeMap<Character,Integer>();
Set<Character> st = tm.keySet();
char
[] c = s.toCharArray();
for
(
int
x=
0
;x<c.length;x++)
{
if
(!st.contains(c[x]))
{
tm.put(c[x],
1
);
}
else
{
tm.put(c[x], tm.get(c[x])+
1
);
}
}
printMapDemo(tm);
}
private
static
void
printMapDemo(TreeMap<Character, Integer> tm) {
Set<Character> st = tm.keySet();
Iterator<Character> ti = st.iterator();
for
(;ti.hasNext();)
{
char
key = ti.next();
System.out.println(key+
"("
+tm.get(key)+
")"
);
}
}
}