String[] ks = { "11", "22", "33", "44", "55", "44", "33", "11" };
Map
for (String s : ks) {
if (map.get(s) != null) {
map.put(s, map.get(s) + 1);
} else {
map.put(s, 1);
}
}
System.out.println("统计输出:");
for (String s : map.keySet()) {
System.out.println(" " + s + " : " + map.get(s));
}
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
public class MapTest {
public static void main(String[] args) {
String[] data = {"hello","world","tt","hello","world","hello","world"};
Mapmap = new HashMap ();
for(String str : data){
if(map.containsKey(str)){
map.put(str, map.get(str) + 1);
}else{
map.put(str, 1);
}
}
Iterator it = map.entrySet().iterator();
while(it.hasNext()){
Entry ex = (Entry) it.next();
System.out.println(ex.getKey() + ":" + ex.getValue());
}
}
}