java泛型操作及遍历

package demo;
import java.util.ArrayList;
import java.util.List;
public class whale {
	public static void main(String[] args) {
		List<Zhang> li = new ArrayList<Zhang>();
		Zhang z = new Zhang();
		z.setId(1);
		z.setName("zyy");
		z.setGender("nv");
		li.add(z);
		
		Zhang z2 = new Zhang();
		z2.setId(1);
		z2.setName("zyy2");
		z2.setGender("nv2");
		li.add(z2);
		
		System.out.println(li.size());
		System.out.println(li.toString());
		
		for(int i=0;i<li.size();i++){
			Zhang s = li.get(i);
			System.out.print(s);
		}
	}
}

entity

package demo;
public class Zhang {
	private Integer id;
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getGender() {
		return gender;
	}
	public void setGender(String gender) {
		this.gender = gender;
	}
	private String name;
	private String gender;
}

输出

2
[demo.Zhang@61de33, demo.Zhang@14318bb]
demo.Zhang@61de33demo.Zhang@14318bb

你可能感兴趣的:(java)