Java Mania
Java Mania
LinkedHashMap
How To Use -使用方法-
Source -LinkedHashMapTest.java-
package mania.test;
import java.util.*;
public class LinkedHashMapTest
{
// LinkedHashMapの使用方法
public static void main(String[] args)
{
System.out.println("===実行結果===");
Map map = new LinkedHashMap();
map.put(new Integer(5), "FIVE");
map.put(new Integer(3), "THREE");
map.put(new Integer(4), "FOUR");
map.put(new Integer(1), "ONE");
map.put(new Integer(2), "TWO");
System.out.println("*初期値");
write(map);
// key=4を上書き
System.out.println("*key=4の変更");
map.put(new Integer(4), "NEW FOUR");
write(map);
// key=3を削除
System.out.println("*key=3の削除");
map.remove(new Integer(3));
write(map);
}
public static void write(Map map)
{
Iterator it = map.keySet().iterator();
Object o = null;
while(it.hasNext())
{
o = it.next();
System.out.println(o + ":" + map.get(o));
}
}
}
Results -実行結果-
===実行結果===
*初期値
5:FIVE
3:THREE
4:FOUR
1:ONE
2:TWO
*key=4の変更
5:FIVE
3:THREE
4:NEW FOUR
1:ONE
2:TWO
*key=3の削除
5:FIVE
4:NEW FOUR
1:ONE
2:TWO
Copyright (C) 2006, JavaMania. All Rights Reserved.