5
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JAVA HashMapのKeyを二つにした

Last updated at Posted at 2015-02-14

#HashMapを拡張してみた

キーが二つ欲しかったので、MAPを拡張しました。
座標にデータを紐づけるときとかに便利と思います。

…もしかして標準ですでにこの機能ってあったりする…?

##コード



import java.util.HashMap;

@SuppressWarnings({ "serial", "rawtypes" })
public class HashMapExt<K,V> extends HashMap{
    
    @SuppressWarnings("unchecked")
    public void put(K key1,K key2,V value){
        super.put(key1+","+key2,value);
    }
    
    public String get(K key1,K key2){
        return (String) super.get(key1+","+key2);
    }
}


5
7
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?