java中hashmap容器
package nuc.ss;
public class m {
private String name,password;
public m() {
super();
// TODO Auto-generated constructor stub}
public m(String name, String password) { super();
this.name = name;
this.password = password;}
public String getName() {
return name;}
public void setName(String name) { this.name = name;}
public String getPassword() {
return password;}
public void setPassword(String password) { this.password = password;}
@Override
public String toString() {
return “m [name=” + name + “, password=” + password + “]”;} }
package nuc.ss;
import java.util.*;
public class Testm2 {
public static void main(String args[]){ Set a = new HashSet();
m b1 = new m(“科比”,“1111”);
m b2 = new m(“库里”,“1111”);
m b3 = new m(“詹姆斯”,“1111”); a.add(b1); a.add(b2); a.add(b3);
//由于set方法不能使用普通for循环来遍历,所以使用Object
Object[] o = a.toArray();
for(int i=0;i<o.length;i++){ System.out.println(o[i]); } }}