TreeSet problems

finalfantasy0915 2010-02-12 02:20:04
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();
}
}
}



...全文
131 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
bobo364 2010-02-15
  • 打赏
  • 举报
回复
netbeans测试通过, tree.add(new Demo().new Customer("Schmidt", 48597));
这个的参数传递的也不对
bobo364 2010-02-15
  • 打赏
  • 举报
回复
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package exp1;

/**
*
* @author 波
*/
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);
}

TreeSet tree = new TreeSet();

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

Iterator iter2 = tree.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();
}
}
}
knightzhuwei 2010-02-15
  • 打赏
  • 举报
回复
或者这样晦涩点
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);
}

TreeSet treeSet=new TreeSet();

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

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

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();
}
}
}
knightzhuwei 2010-02-15
  • 打赏
  • 举报
回复
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);
}

TreeSet treeSet=new TreeSet();

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

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


}

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();
}
}
finalfantasy0915 2010-02-15
  • 打赏
  • 举报
回复
Sorry for the silly mistakes. I have been practicing the java by not using the IDE tools to gain a better understanding of this language. I have fixed the errors but still have some errors needed to be fixed.

========================================
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);
}

TreeSet treeSet=new TreeSet();

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

Iterator iter2=treeSet.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();
}
}
}



The error message is "No enclosing instance of type Demo is accessible. Must qualify the allocation with an enclosing instance of type Demo (e.g. x.new A() where x is an instance of Demo)."
yueguangkai001 2010-02-12
  • 打赏
  • 举报
回复
..................
我发觉了一个问题,好多人还在用手写JAVA代码,没有用过IDE
knightzhuwei 2010-02-12
  • 打赏
  • 举报
回复
"TreetSet cannot be resolved or is not a type".

这么明显的事情 是你拼错了 应该是TreeSet
源码链接: https://pan.quark.cn/s/0f7c75cb3aad ### MIPI Video Mode 与 Command Mode 的差异 #### 一、引言 MIPI (Mobile Industry Processor Interface) 是一种用于连接移动设备中处理器及其外围设备的标准化接口。MIPI 接口支持多种协议,其中包含 DSI (Display Serial Interface) 和 DCS (Display Control Interface) 等协议。在 MIPI 接口的应用中,主要涉及两种工作模式:Video Mode(视频模式)和 Command Mode(命令模式)。本文旨在系统性地阐述这两种模式的工作机制、特性以及实际应用环境。 #### 二、LCD RAM 概念说明 在进一步探讨 MIPI 的两种模式之前,有必要对文中提及的“LCD RAM”概念进行明确。实际上,“LCD RAM”并非一个通用术语,而是本文作者用来描述 LCD 控制器中用于存储显示数据的内存区域。LCD(Liquid Crystal Display,液晶显示屏)通常配备一个控制 IC(Integrated Circuit,集成电路),该控制 IC 可能内置 RAM 以缓存显示数据。 #### 三、MIPI Video Mode(视频模式) **定义:** - 视频模式是一种类似于传统 RGB 接口的工作模式,它要求主机持续不断地向显示器传输刷新数据。 - 在这种模式下,数据和控制信号以报文的形式通过 MIPI 总线进行传输。 - 显示器本身无需配备帧缓冲器,因为主机会周期性地刷新屏幕。 **特点:** 1. **实时性高:** 主机需要不...
源码下载地址: https://pan.quark.cn/s/a4b39357ea24 在电磁模拟技术中,CST(Computer Simulation Technology)是一种被广泛采纳的软件工具,它主要用于电磁场、微波、天线以及射频系统的设计工作。本资料将详细分析CST软件中离散端口的具体配置方法,这些方法对于提升仿真结果的精确度和专业水准具有决定性作用。离散端口在CST软件中扮演着模拟信号输入或输出的重要角色,它们构成了仿真模型不可或缺的部分。在配置离散端口时,一个核心的原则是保证端口的方向与网格线保持一致,这是因为这样做能够有效降低计算过程中产生的误差,并确保仿真数据的有效性。如果未能遵循这一指导原则,可能会引发未知的计算问题,进而导致仿真结果失去可靠性。 在CST软件中配置离散端口,通常需要借助“Pick Points”这一功能。通过选择“Pick Edge Center”选项,端口将被设定在模型边缘的中心位置上。然而,这种做法并不总是能够确保端口与网格线保持平行。在某些特定情形下,模型的几何构造可能不允许直接选取一个与网格线平行的边作为端口的安装位置。 为了克服这一挑战,可以采用多种不同的策略。如果模型本身已经包含一条与馈电口平行的边,那么可以直接利用这条边来建立端口,此时CST软件会自动调整端口使其与网格线对齐。另一种可选的方法是,当模型不具备现成的平行边时,用户可以手动构建一个几何结构,比如一个立方体,并使其边缘与馈电口平行。通过这种方式,新建立的几何结构的边缘就可以作为端口的位置,从而确保端口与网格线的平行关系。 在实施上述操作时,必须关注端口尺寸的合理性和物理意义的一致性。端口的尺寸应当依据实际天线馈电部分的尺寸进行适当调整,过大的端口或...

62,622

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧