HashMap に難儀する

| コメント(0)

HashMap で以下の様にコーディングした。

HashMap map = new HashMap();
map.put("key1", new Integer(1));
map.put("key2", new Integer(2));
map.put("key3", new Integer(3));
map.put("key4", new Integer(4));
map.put("key5", new Integer(5));
map.put("key6", new Integer(6));
map.put("key7", new Integer(7));
map.put("key8", new Integer(8));
map.put("key9", new Integer(9));
map.put("key10", new String("10"));
map.put("key11", new String("11"));
map.put("key12", new String("12"));
map.put("key13", new String("13"));
map.put("key14", new String("14"));
map.put("key15", new String("15"));
map.put("key16", new String("16"));
map.put("key17", new String("17"));
map.put("key18", new String("18"));
map.put("key19", new String("19"));

当然 map の中には19個のオブジェクトが存在するはずだが、何故か15個しかない。Integerだけならおかしくないようだが、その後の String でキーが異なるにもかかわらず上書きされてしまうようなのだ。

以下エクリプスのデバッガで取得したもの。
ECLIPSE 2.1.3 / JDK 1.4.2.03

map= HashMap (id=21)
entrySet= HashMap$EntrySet (id=50)
keySet= null
loadFactor= 0.75
modCount= 19
size= 19
table= HashMap$Entry[32] (id=26)
[0]= null
[1]= HashMap$Entry (id=28)
[2]= HashMap$Entry (id=31)
[3]= null
[4]= null
[5]= null
[6]= null
[7]= null
[8]= null
[9]= HashMap$Entry (id=32)
[10]= HashMap$Entry (id=33)
[11]= null
[12]= null
[13]= HashMap$Entry (id=34)
[14]= HashMap$Entry (id=35)
[15]= HashMap$Entry (id=36)
[16]= HashMap$Entry (id=37)
[17]= null
[18]= null
[19]= null
[20]= HashMap$Entry (id=38)
[21]= null
[22]= null
[23]= HashMap$Entry (id=39)
[24]= HashMap$Entry (id=40)
[25]= null
[26]= HashMap$Entry (id=41)
[27]= HashMap$Entry (id=42)
[28]= null
[29]= HashMap$Entry (id=43)
[30]= HashMap$Entry (id=44)
[31]= null
threshold= 24
values= null

何が原因か全然わからない。
別のマシンで動作させるとちゃんと19個だったりするのでタチが悪い(^^;

コメントする

ウェブページ

  • about
Powered by Movable Type 5.2.10

このブログ記事について

このページは、よしが2004年8月 3日 08:15に書いたブログ記事です。

ひとつ前のブログ記事は「暴風雨の中でバーベQ」です。

次のブログ記事は「光学マウス」です。

最近のコンテンツはインデックスページで見られます。過去に書かれたものはアーカイブのページで見られます。