怎么从List<Dictionary<gt;gt;取Dictionary<gt;的key键值
展开全部
由于 java.util.Dictionary 循环的时候 需要通过Enumeration
我们来看 示例:
public static void main(String[] args){
//************构造数据************************
List<Dictionary<String, String>> list = new ArrayList<Dictionary<String, String>>();
Dictionary<String, String> dictionary = new Hashtable<String, String>();
dictionary.put("name", "飞天奔月");
dictionary.put("age", "永远18");
list.add(dictionary);
//***********将key 装到list里面去********************
List<String> dictionaryKeys = new ArrayList<String>();
for (Dictionary<String, String> dictionaryLoop : list){
Enumeration<String> keys = dictionaryLoop.keys();
while (keys.hasMoreElements()){
String key = keys.nextElement();
dictionaryKeys.add(key);
}
}
//**********输出*****************************************
System.out.println(dictionaryKeys.toString());
}
输出:
[age, name]
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询