java - How can I get the values from Map<String List<Object>> -


i have model class employeebasedata.java looks (this example):

public class employeebasedata { public employeebasedata(string sid){     this.sid = sid;  } private string sid; private int actualhours = 10; private int regularhours = 9; private int overtime = 1; public string getsid() {     return sid; } public void setsid(string sid) {     this.sid = sid; } public int getactualhours() {     return actualhours; } public void setactualhours(int actualhours) {     this.actualhours = actualhours; } public int getregularhours() {     return regularhours; } public void setregularhours(int regularhours) {     this.regularhours = regularhours; } public int getovertime() {     return overtime; } public void setovertime(int overtime) {     this.overtime = overtime; } 

this controller:

public class inputcontroller {  public static void main(string[] args) {      try {          map<string, list<object>> employeemap = new hashmap<string, list<object>>();         employeebasedata base_data1 = new employeebasedata("e774801");         employeebasedata base_data2 = new employeebasedata("e774802");         list<object> valsetone = new arraylist<object>();         list<object> valsettwo = new arraylist<object>();         valsetone.add(base_data1);         valsettwo.add(base_data2);         employeemap.put("e774801", valsetone);         employeemap.put("e774802", valsettwo);         for(map.entry<string, list<object>> entry : employeemap.entryset()){             string key = entry.getkey();             list<object> value= entry.getvalue();          } 

now question if need access getovertime() method of model, how can map?

@epoch has right idea regard proper definition of map. it's worth pointing out, however, java 8 gives elegant way of getting overtimes, without having write cumbersome loops:

list<integer> overtimes =      employeemap.values()                .stream()                .flatmap(collection::stream)                .map(employeebasedata::getovertime)                .collect(collectors.tolist()); 

Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -