µ¥ÀÌÅÍ Áߺ¹È½¼ö ±¸Çϱâ
MapTest2.java
import java.util.*;
public class MapTest2 {
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);
}
}
D:\java\util\>javac MapTest2.java
D:\java\util\>java MapTest2 a b a c c c d a e
{b=1, a=3, e=1, d=1, c=3}
{a=3, b=1, c=3, d=1, e=1}
mapÀ» »ç¿ëÇÑ µ¥ÀÌÅÍÀÇ ÀúÀå°ú µ¥ÀÌÅÍ Áߺ¹È½¼ö ±¸ÇÏ±â ¹× Á¤·Ä
jabookÀúÀÚ¸íÇÔ |
Á¦¸ñ:¼Ò¼³°°Àº¹Ì´ÏÄÚµå ÀÛ¼ºÀÚ:Àںϸâ¹ö ±è¿Ï±â |