zoukankan      html  css  js  c++  java
  • HashMap中的内容进行迭代输出

    package demo20130418;
    import java.util.HashSet;
    import java.util.Iterator;
    import java.util.Map;
    import java.util.HashMap;
    import java.util.Map.Entry;
    import java.util.Set;
    public class MapDemo {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		Map<Integer,User> map=new HashMap<Integer,User>();
    		User user=new User(1,"ctl","qq.com",'m');
    		map.put(user.getId(), user);
    		user=new User(2,"lr","qq.com",'w');
    		map.put(user.getId(), user);
    		System.out.println(map);
    		Set<Entry<Integer,User>> set=map.entrySet();
    		Iterator it=set.iterator();
    		for(;it.hasNext();){
    			System.out.println(it.next());
    		}
    				//new HashSet<Entry<Integer,User>>();
    		//Iterator<Integer,User> iterator=map
    	}
    
    }
    class User{
    	private int id;
    	private String name;
    	private String email;
    	private char sex;
    	public User(int id, String name, String email, char sex) {
    		super();
    		this.id = id;
    		this.name = name;
    		this.email = email;
    		this.sex = sex;
    	}
    	public int getId() {
    		return id;
    	}
    	public void setId(int id) {
    		this.id = id;
    	}
    	public String getName() {
    		return name;
    	}
    	public void setName(String name) {
    		this.name = name;
    	}
    	public String getEmail() {
    		return email;
    	}
    	public void setEmail(String email) {
    		this.email = email;
    	}
    	public char getSex() {
    		return sex;
    	}
    	public void setSex(char sex) {
    		this.sex = sex;
    	}
    	public String toString(){
    		return id+" "+name+" "+email+" "+sex;
    	}
    }


  • 相关阅读:
    MongoDB 4.0.10 CRUD操作(增删改查)
    MongoDB 4.0.10 聚合
    MongoDB 4.0.10 索引
    MongoDB 4.0.10 导出、导入,备份、恢复
    MongoDB 4.0.10 监控
    列及注释
    SecureCRT的shell中文乱码
    oracle 判断是否是日期
    查询oracle服务器的版本
    Oracle中connect by 的执行结果记载
  • 原文地址:https://www.cnblogs.com/xinyuyuanm/p/3029555.html
Copyright © 2011-2022 走看看