import java.util.*;
public class ex_65{
private String s;
public ex_65(String s){
this.s = s;
}
public boolean equals(Object o){
if(this.s.equals(((ex_65)o).s))
return true;
else
return false;
}
public int hashCode(){
return this.s.hashCode();
}
public static void main(String args[]){
HashSet<Object> hs = new HashSet<Object>();
ex_65 ws1 = new ex_65("abc");
ex_65 ws2 = new ex_65("abc");
String s1 = new String("abc");
String s2 = new String("abc");
hs.add(ws1);
hs.add(ws2);
hs.add(s1);
hs.add(s2);
System.out.println(hs.size());
}
}
------------------------------------------
3
------------------------------------------
加上畫黑部分:
------------------------------------------
2
------------------------------------------
沒有留言:
張貼留言