// <= Java 1.4
HashMap map = new HashMap();
map.put("apple", "red");
map.put("banana", "yellow");
map.put("grape", "purple");
Iterator iter = map.entrySet().iterator();
while (iter.hasNext()) {
Entry entry = (Entry) iter.next();
System.out.println("key : " + entry.getKey() + " / value : " + entry.getValue());
}
// >= Java 1.5
Map<String, String> mp = new HashMap<String, String>();
mp.put("apple", "red");
mp.put("banana", "yellow");
mp.put("grape", "purple");
for (Map.Entry<String, String> entry: mp.entrySet()) {
System.out.println("key : " + entry.getKey() + " / value : " + entry.getValue());
}
# Ruby
hs = { "apple" => "red", "banana" => "yellow", "grape" => "purple" }
hs.each { |key, value| puts "key : #{key} / value : #{value} }
2008년 8월 8일 금요일
hash, hashmap 비교
사내 게시판에 Ruby script 샘플 소개하면서 이해 돕기위해 hash/HashMap 비교한거.
피드 구독하기:
글 (Atom)