• 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;
    	}
    }


  • 相关阅读:
    nfs共享目录及sersync实时同步
    rsync备份
    MySQL基础操作
    源码包安装MySQL
    二进制安装MySQL
    Centos6防火墙-iptables版
    linux系统mongdb基础(1)
    linux系统ElK基础filebeat收集日志(4)
    linux系统ElK基础(3)
    linux系统ElK基础(2)
  • 原文地址:https://www.cnblogs.com/xinyuyuanm/p/3029555.html
Copyright © 2020-2023  润新知