TreeSet problems

finalfantasy0915 finalfantasy0915 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
Hi,

I encountered some problems when i am learning the treeSet. The following is the code. Could anyone help me please?

The error messages are "TreetSet cannot be resolved or is not a type". I couldn't tell the problems. Thank you.


======================================
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

public class Demo {
public static void main(String[] args){
HashMap hashMap=new HashMap();

hashMap.put("Schmidt","+49 6227 48597");
hashMap.put("Mayer","+49 6221 1808");
hashMap.put("Schmidt","+49 40 364850");
hashMap.put("Treusch","+49 89 98965456");

Set keys= hashMap.keySet();
Iterator iter=keys.iterator();

while (iter.hasNext()){
String key=(String) iter.next();
String value=(String) hashMap.get(key);
System.out.println("key: "+key+"\tvalue: "+value);
}

TreetSet treetSet=new TreetSet();

treetSet.add(new Customer("Schmidt",48597));
treetSet.add(new Customer("Mayer",180));
treetSet.add(new Customer("Schmidt",3648));

Iterator iter2=treetSet.iterator();
while (iter2.hasNext()){
Customer customer=(Customer)iter2.next();
System.out.println(customer.getName());
}
}

public class Customer implements Comparable{
private String name;
private int id;

public Customer(String name, int id){
this.name=name;
this.id=id;
}

public int getId(){
return id;
}

public String getName(){
return name;
}

public int compareTo(Object otherCustomer){
return this.id=((Customer)otherCustomer).getId();
}
}
}



...全文

相关推荐

评论 7
收藏 已收藏
分享
返回顶部
finalfantasy0915
Java SE 62,620 成员 307,251 内容