2015年9月30日 星期三

Map 應用


import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class MapDemo {
    public static void main(String[] args){
    
        Map<String, String> shirtList = new TreeMap<>();
        shirtList.put("S001", "Blue Shirt");
        shirtList.put("S002", "Black Shirt");
        shirtList.put("S003", "Gray Shirt");
        
        Set<String> keys = shirtList.keySet();
        System.out.println("====== Shirt List ======");
        for (String key : keys){
            System.out.println("Part#: " + key + " " 
                               + shirtList.get(key));
        } 
    }
}