TreeSet problems
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();
}
}
}
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();
}
}
}
...全文
相关推荐
leetcode_problems
**树与图** - **二叉树**:包括二叉搜索树、平衡树(AVL树、红黑树)等,Java的TreeSet和TreeMap类是基于二叉搜索树实现的。
code-problems:面试编码问题的解决方案
本篇将针对"code-problems:面试编码问题的解决方案"这一主题,详细探讨Java面试中的常见编码挑战及其解法。一、数据结构与算法1.
练习题:练习题
在"Practice-Problems-main"这个压缩包中,很可能会包含针对上述知识点的编程练习题,通过解题可以提升你的编程能力。
Java_中游的.zip
**集合框架**:Java的集合框架包括List(如ArrayList、LinkedList)、Set(如HashSet、TreeSet)和Map(如HashMap、TreeMap)。
leetcode2-LeetCode:力码
leetcode2力码1.LC日志2.数据结构数组——待办事项数组(固定),动态数组链表TreeSet/TreeMap(有序)HashSet/HashMap(无序)堆/优先队列双端队列/队列/堆栈对/


Java SE
