Hashmap holding different data types as values for instance Integer, String and Object

前端 未结 5 1204
别那么骄傲
别那么骄傲 2020-12-12 12:11

I need to create a hashmap with key as integer and it should hold multiple values of different data types. For example if the key is msg id and the values are

5条回答
  •  再見小時候
    2020-12-12 12:41

    Define a class to store your data first

    public class YourDataClass {
    
        private String messageType;
        private Timestamp timestamp;
        private int count;
        private int version;
    
        // your get/setters
        ...........
    }
    

    And then initialize your map:

    Map map = new HashMap();
    

提交回复
热议问题