我在JAVA里面写了一个list合集,我想要用map类型初始化list里面的东西

public static void main(String[] args) {

// TODO Auto-generated method stub

ArrayList<TestLzp> lzp = new ArrayList<TestLzp>();
TestLzp tzd = new TestLzp("",0);
就是这里,我想要用map初始化一下我lzp里面的信息

Portlet portlet = new Portlet(); //Portlet 你的TestLzp
JSONObject jsonObject = JSONObject.fromObject(portlet); // net.sf.json.JSONObject
Map map = new HashMap();
for (Object objectKey : jsonObject.keySet()){
   String value = String.valueOf(jsonObject.get(objectKey));
   map.put(objectKey,value);
}
System.out.println(map.toString());

温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-08-18
HashMap<String, Integer> hm = new HashMap<String, Integer>();
hm.put("", 0);
没怎么看懂问题, 你的TestLzp 是自定义类,构造器是(String,Integer)吧,
第2个回答  2017-08-18
你的意思是把list里的TestLzp对象,存到map中吗?
Map map=new HashMap();
for(Integer i=0;i<lzp .size();i++){
map1.put(i, lzp .get(i));
}
第3个回答  2016-06-26
TestLzp 这个类的定义是怎样的?不好理解啊。
第4个回答  2017-08-18
抱歉 只会 C++
相似回答