TreeSet在集合中 [英] TreeSet In Collection

查看:64
本文介绍了TreeSet在集合中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

import java.util.TreeSet;
class TreeSetExample
{
  public static void main(String... args)
  {
    TreeSet <Integer>ts = new TreeSet<Integer>();
    ts.add(1092);
    ts.add(1);
    ts.add(11);
    ts.add(1);
    System.out.println(ts);
  }
}



当我运行上面的代码时运行正常但是当我尝试在代码下面运行时会出错。


when i run above code its run fine but when i try to run below code its give an error.

import java.util.*;
class TreeSetExample
{
  public static void main(String... args)
  {
    TreeSet <Integer>ts = new TreeSet<Integer>();
    ts.add(1092);
    ts.add(1);
    ts.add(11);
    ts.add(1);
    System.out.println(ts);
  }
}




Error---
<pre>TreeSetExmaple.java:6: cannot access TreeSet
bad class file: .\TreeSet.java
file does not contain class TreeSet
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
TreeSet <Integer>ts = new TreeSet<Integer>();
^
1 error

推荐答案

然后导入特定的Treeset。这就是IDE(*)为您所做的。你不需要关心它。



(*)Eclipse / Netbeans



编辑:如果没有正确指定,编译器可能无法找到TreeSet。

通常有来自不同包/库的不同类似命名对象。

导入由IDE执行它输入了所需要的东西。
Then import the specific Treeset. That''s what the IDE (*) does for you. You do not need to care for that.

(*) Eclipse / Netbeans

the compiler might not be able to find TreeSet if not specified correctly.
One often has different similar named objects from different packages / libs.
The import is carried out by the IDE, it imports preciously what is needed.


谢谢TorstenH ......

实际上我在记事本上尝试这个程序......
Thanks TorstenH ...
Actually i try this program on notepad...


这篇关于TreeSet在集合中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆