I want to iteate List and If that key is "Happy" then I want to store that in a variable.
Eg:- List<Map> list=service.getValues();
I want to iteate List and If that key is "Happy" then I want to store that in a variable.
Eg:- List<Map> list=service.getValues();
first of all DONT USE RAW Types
after that, do an enhance for loop to iterate the list, every element is a map, then get the entrySet of that
List<Map<String, String>> list = ...;
for (final Map<String, String> element : list) {
for (final Entry<String, String> entryElem : element.entrySet()) {
System.out.println("Key: " + entryElem.getKey());
System.out.println("Value: " + entryElem.getValue());
}
}
the nested for loops can be resumed to:
list.forEach(element-> element.entrySet().forEach(System.out::println));
I just traversed the list. Getting the map then travesring the map.
String output="";
List<Map<String,String>> list=new ArrayList<Map<String,String>>();
for(int i=0;i<list.size();i++)
{
Map<String,String> map=list.get(i);
Set<String> set=map.keySet();
Iterator it=set.iterator();
while(it.hasNext())
{
String key=(String) it.next();
if(key.equals("Happy"))
output=map.get(key);
}
}
String var=null;
List<Map> list=new ArrayList<Map>(0);
for(Map map:list){
for(Object key:map.keySet()){
String obj=key.toString();
if(obj.equals("Happy"))
{
var=key;
System.out.println(var);
}
}
}
List<Map> list = service.getValues();
for(Map map : list) {
for(String key : map.keySet()) {
if(key.equals("Happy")) {
//do something with key
}
}
}