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; } }
时间: 2024-10-21 07:53:50