1.

public class MapAction extends ActionSupport{
    private Map<String, User> map = new HashMap<>();

    public Map<String, User> getMap() {
        return map;
    }

    public void setMap(Map<String, User> map) {
        this.map = map;
    }
    
    @Override
    public String execute() throws Exception {
        //方法一:通过Entry遍历<迭代Entry>
        for(Entry<String, User> entry : map.entrySet()) {
            System.out.println(entry.getKey()+":"+entry.getValue().getUsername());
        }
        //方法二:通过Set集合遍历<迭代Set>
        for(String key: map.keySet()){
            System.out.println(key + ":" + map.get(key).getPassword());
        }
        
        return SUCCESS;
    }
    
}

 

相关文章:

  • 2021-08-27
  • 2022-12-23
  • 2021-11-30
  • 2021-12-01
  • 2021-06-11
  • 2021-09-07
  • 2022-12-23
  • 2021-11-30
猜你喜欢
  • 2021-09-11
  • 2022-12-23
  • 2021-12-15
  • 2021-07-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案