【发布时间】:2016-05-06 07:09:17
【问题描述】:
我正在尝试解决这个问题,但我现在在这里停留了一段时间。我的问题是我找不到如何将数组对象放入我的哈希图的方法。
这是我从 google 获得的下拉菜单的 hashmap 示例代码。
private Map<String,Map<String,String>> data2 = new HashMap<String,Map<String,String>>();
private String country;
private String city;
private Map<String, String> countries;
private Map<String,String> cities;
countries = new HashMap<String, String>();
countries.put("USA", "USA");
countries.put("Germany", "Germany");
countries.put("Brazil", "Brazil");
Map<String,String> map = new HashMap<String, String>();
map.put("New York", "New York");
map.put("San Francisco", "San Francisco");
map.put("Denver", "Denver");
data2.put("USA", map);
map = new HashMap<String, String>();
map.put("Berlin", "Berlin");
map.put("Munich", "Munich");
map.put("Frankfurt", "Frankfurt");
data2.put("Germany", map);
现在.. 我的问题是如何将我的对象放入 hashmap 中。
这是我获取数组对象的代码。
while(rs.next()){
PropertyData reader = new PropertyData();
id = rs.getInt("id");
prop_name = rs.getString("prop_name");
prop_value = rs.getString("prop_value");
engine_name = rs.getString("engine_name");
//other setter..
reader.setId(id);
reader.setPropName(prop_name);
reader.setPropValue(prop_value);
reader.setEngineName(engine_name);
//other setter..
prop.add(reader);
}
从上面的代码。我想将 id 放在 hashmap 键上,将 propname 放在 hashmap 字符串名称上。选择后,我想显示引用 id 的其他值。
这是我的对象被添加的地方。
static List<PropertyData> prop = new ArrayList<PropertyData>();
我试图在我的 hashmap 上初始化它,但它返回 null。
【问题讨论】:
-
不可能知道你想做什么,问更好的问题,发布一些完整的代码(准备运行)并展示你的问题。
-
只要说出你想放的什么和你想放的哪里就足够了。 2行代码。
-
好吧,等我编辑一下