}
Set<Character> set=tp.keySet();
Iterator<Character> it=set.iterator();
while (it.hasNext())
{
Character key = it.next();
Integer value=tp.get(key);
System.out.print(key+"("+value+")");
}
}
}
这是第二种方法,使用的是结合正则表达式做的
你可以参考下:
public class Test2
{
public static void main(String[] args )
{
String str="abcdabcdfgr";
String st1 = str.replaceAll("(?s)(.)(?=.*\\1)", "");
String st2=st1.replaceAll("[0-9]", "");
//System.out.println(st2);
String st;
for (int i = 0; i <st2.length(); i++)
{
st=st2.substring(i,i+1);
int index=show(str,st);
System.out.print(st+"("+index+")");
}
}
public static int show(String str,String st)
{
int count=0;
for (int j =0; j< str.length(); j++)
{
String s=str.substring(j, j+1);
if (st.equals(s))
{
count++;
}