Using two (or more) objects as a HashMap key

前端 未结 8 1197
借酒劲吻你
借酒劲吻你 2020-12-13 21:51

I want to store certain objects in a HashMap. The problem is, usually you just use a single object as a key. (You can, for example, use a String.) What I want to do it to us

8条回答
  •  轮回少年
    2020-12-13 22:22

    You could create a holder class that contains the class and string that you want as the keys.

    public class Key {
    
        public MyClass key_class;
        public String key_string;
    
        public Key(){
            key_class = new MyClass();
            key_string = "";
        }
    
    }
    

    Probably not the best solution, but a possibility.

提交回复
热议问题