public class Mytest { public static void main(String[] args) {
String aa = "this is a pig";
Map temp = new HashMap();
for (int i = 0; i < aa.length(); i++) {
String a = aa.substring(i, i+1);
if (temp.get(a) == null) {
temp.put(a, new Integer(1));
} else {
int count = ((Integer) temp.get(a)).intValue();
temp.put(a, new Integer(count + 1));
}
}
Set dataSet = temp.entrySet();
Iterator iter = dataSet.iterator();
while (iter.hasNext()) {
System.out.println(iter.next());
}
}
}
String aa = "this is a pig";
Map temp = new HashMap();
for (int i = 0; i < aa.length(); i++) {
String a = aa.substring(i, i+1);
if (temp.get(a) == null) {
temp.put(a, new Integer(1));
} else {
int count = ((Integer) temp.get(a)).intValue();
temp.put(a, new Integer(count + 1));
}
}
Set dataSet = temp.entrySet();
Iterator iter = dataSet.iterator();
while (iter.hasNext()) {
System.out.println(iter.next());
}
}
}
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry)iter.next();
System.out.println(entry.getKey() + "'s count is " + entry.getValue());
}
int[] counts = new int[128];
byte[] bytes = s.getBytes();
for(int i=0; i<bytes.length; i++)
counts[0x7f & bytes[i]]++;
for(int i=0; i<counts.length; i++)
{
if(counts[i] != 0)
System.out.println(((char) i) + "=" + counts[i]);
}
zhong xie
import java.util.*;
如有冒犯,还请见谅.