package day16;
import java.util.Vector;
public class Demo1 {
public static void main(String[] args) {
Vector vec = new Vector();
}
}
package day16;
import java.util.HashSet;
import java.util.Set;
class Person{
int id ;
String name;
public String toString(){
return "ID:"+this.id+"Name:"+this.name;
}
public Person(int id , String name){
this.id = id;
this.name = name;
}
@Override
public int hashCode(){
return this.id;
}
@Override
public boolean equals(Object o ){
Person p = (Person) o;
return this.id==p.id;
}
}
public class Demo2 {
public static void main(String[] args) {
Set set = new HashSet();
set.add(new Person(123,"aaaaa"));
set.add(new Person(2222,"ffff"));
set.add(new Person(123,"aaaaa"));
System.out.println(set);
}
}
package day16;
public class Demo3 {
public static void main(String[] args) {
String str = "hello";
String str2 = new String("hello");
System.out.println("same?---"+(str==str2));
System.out.println("str hashcode : "+str.hashCode());
System.out.println("str hashcode : "+str2.hashCode());
}
}
package day16;
import java.util.TreeSet;
public class Demo4 {
public static void main(String[] args) {
TreeSet tree = new TreeSet();
tree.add(1);
tree.add(2);
tree.add(4);
tree.add(6);
tree.add(11);
tree.add(16);
System.out.println(tree);
}
}