HashMapの使い方を自分用にメモすることにしました。
[ 使い方 ]
宣言
KeyがString型でValueがInteger型のHashMapとしてHashMapTestを宣言します。
HashMap<String, Integer> HashMapTest = new HashMap<String, Integer>();
初期化
HashMapTestを初期化します。
HashMap<String, Integer> HashMapTest = new HashMap<String, Integer>() {{ put("abc", 0); put("def", 1); put("ghi", 2); }};
要素の消去
HashMapTestからKeyが"abc"の要素を消去します。
HashMapTest.remove("abc");
全要素の消去
HashMapTestの全要素を消去します。
HashMapTest.clear();
長さを取得
HashMapTestの長さを取得します。
HashMapTest.size();
特定の要素を含むか
HashMapTestがKeyが"abc"の要素を含むかを求めます。
HashMapTest.containsKey("abc");