import java.util.*;
public class HashMapTest {
public static void main(String args[]) {
Map map = new HashMap();
Integer hana = new Integer(1);
for (int i=0, n = args.length; i<n; i++) {
String key = args[i];
Integer freq = (Integer)map.get(key);
if (freq == null) {
freq = hana;
}
else {
int value = freq.intValue();
freq = new Integer(value + 1);
}
map.put(key, freq);
}
System.out.println(map);
Map sortedMap = new TreeMap(map);
System.out.println(sortedMap);
}
}
public class HashMapTest {
public static void main(String args[]) {
Map map = new HashMap();
Integer hana = new Integer(1);
for (int i=0, n = args.length; i<n; i++) {
String key = args[i];
Integer freq = (Integer)map.get(key);
if (freq == null) {
freq = hana;
}
else {
int value = freq.intValue();
freq = new Integer(value + 1);
}
map.put(key, freq);
}
System.out.println(map);
Map sortedMap = new TreeMap(map);
System.out.println(sortedMap);
}
}
댓글 없음:
댓글 쓰기