import java.util.*;
class Student// implements Comparable<Student>
{
private String name;
private int age;
Student(String name,int age)
{
this.name=name;
this.age=age;
}public String getName()
{
return name;
}public int getAge()
{
return age;
}
public String toString()
{
return name+"::"+age;
}
/* public int compareTo(Student s)
{
int num=new Integer(s.age).compareTo(new Integer(this.age));
if(num==0)
return this.name.compareTo(s.name);
return num;
}
public int hashCode()
{
return name.hashCode()+age*13;
}
public boolean equals(Object obj)
{
if(!(obj instanceof Student))
throw new Exception("类型不一致");
Student sd=(Student)obj;
return this.name.equals(sd.name) && this.age==sd.age;}*/}
class a{
public static void main(String[] args){
HashMap<Student,String> tm=new HashMap<Student,String>();
tm.put(new Student("4zhangsan1",21),"哈4哈");
tm.put(new Student("3zhangsan2",22),"哈3哈");
tm.put(new Student("2zhangsan4",21),"哈8哈");
tm.put(new Student("1zhangsan5",22),"哈dsfasdfasd哈");
tm.put(new Student("1zhangsan5",22),"哈5哈");
Iterator<Student> it=tm.keySet().iterator();
while(it.hasNext()){
Student s=it.next();
String ss=tm.get(s);
System.out.println(s+":::"+ss);}}}//重复元素了 |