Accessing a HashMap from a different class

前端 未结 6 1555
暗喜
暗喜 2020-12-30 08:02

I have a hashmap in my class titled DataStorage:

HashMap people = new HashMap();

people.put(\"bob\", 2);
peopl         


        
6条回答
  •  鱼传尺愫
    2020-12-30 08:33

    This is eazy

    public class ListDataStorage {
    
                public static LinkedHashMap getHmapCashType(){
    
                    LinkedHashMap hMapCashType = new LinkedHashMap();
                    hMapCashType.put("A", "Cash");
                    hMapCashType.put("B", "Credit");
    
                    return hMapCashType;
                }
        }
    

    access hashmap data from another class

    String value = ListDataStorage.getHmapCashType().get("A").toString()
    

提交回复
热议问题