:: reverse dictionary ::
※ソースファイルについて
◎各マークの意味
Pb:pubic Pr:protected S:static
マップのキーの個数を求めるには、Map インターフェースを実装したクラスの size メソッドを使います。
import java.util.Hashtable; import java.util.Map;
Map map = new Hashtable(); map.put("プログラミング言語", "Java"); map.put(new Integer(1), new Integer(12345)); map.put(new Integer(2), new Double(String.valueOf(6.789))); map.put(new Integer(3), new Boolean(true)); int size = map.size();
size は 4 になります。
java.util.Map Pb int size()
マップのキーの個数を求めます。
(キーの個数 = 値の個数)
キーの個数
null キーを格納できるクラスでは、null キーも個数に含まれます。
import java.util.HashMap; import java.util.Map;
Map map = new HashMap(); map.put("プログラミング言語", "Java"); map.put(new Integer(1), new Integer(12345)); map.put(new Integer(2), new Double(String.valueOf(6.789))); map.put(new Integer(3), new Boolean(true)); map.put(null, "NULL"); int size = map.size();
size は 5 になります。
HashMap クラスは null キーを格納できますが、Hashtable クラスは null キーを格納できません。
Map map = new Hashtable(); map.put(null, "NULL");
例外 NullPointerException が発生します。
Copyright (C) 2005-2007 Noto Watabe. All rights reserved.
e-mail:wmh@always-pg.com