我是一种采用数字列表的方法(例如ArrayList
)并将其转换为排序集(例如TreeSet
)并返回它。我写了代码,但遇到了一些问题。
public TreeSet getSort (ArrayList list){
TreeSet set =new TreeSet(list);
return set;
我的问题主要是:
ArrayList List = new ArrayList();
List.add(5);
List.add(55);
List.add(88);
List.add(555);
List.add(154);
System.out.println("the TreeSet of ArrayList is : " + getSort(List));
您需要有类实例才能调用getSort()
方法或使getSort()
to static
Do like
System.out.println("the TreeSet of ArrayList is : "+ new classname().getSort(List));
或使该方法静态
public static TreeSet getSort (ArrayList list){
TreeSet set =new TreeSet(list);
return set;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)