日期:2014-05-20 浏览次数:20906 次
//Usercenter public class Usercenter { private String id;//用户名 private String password;//密码 private String email;//邮箱 static List <Object> list = new ArrayList<Object> (); //id public void setId (String id){ this.id=id; } public String getId (){ return id; } //password public void setPassword (String password){ this.password=password; } public String getPassword (){ return password; } //email public void setEmail (String email){ this.email=email; } public String getEmail (){ return email; }
//添加到list Usercenter use2 = new Usercenter(); // 第一次添加 use2.setIdnum(01);// 获得学号 use2.setId("张三");// 姓名 use2.setPassword("1234");//密码 use2.list.add(use2.getIdnum()); use2.list.add(use2.getId()); use1.setPassword("abcd");//密码 // 第二次添加 Usercenter use1 = new Usercenter(); use1.setIdnum(02);// 获得学号 use1.setId("李四");// 姓名 use2.list.add(use2.getPassword); // 放入list use1.list.add(use1.getIdnum()); use1.list.add(use1.getId()); use1.list.add(use1.getPassword);
package coverlist; import java.util.ArrayList; import java.util.List; /** * @author Yanhua.Chen * @time 2012-8-26 */ public class Usercenter { private String id;//用户名 private String password;//密码 private String email;//邮箱 public static List <Usercenter> list = new ArrayList<Usercenter> (); public Usercenter(){ } public Usercenter(String id){ this.id = id; } //id public void setId (String id){ this.id=id; } public String getId (){ return id; } //password public void setPassword (String password){ this.password=password; } public String getPassword (){ return password; } //email public void setEmail (String email){ this.email=email; } public String getEmail (){ return email; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((id == null) ? 0 : id.hashCode()); return result; } /* * 很重要 * 为了int index = list.indexOf(new Usercenter("id"));他正确 */ @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Usercenter other = (Usercenter) obj; if (id == null) { if (other.id != null) return false; } else if (!id.equals(other.id)) return false; return true; } }