小白,求大佬指导

陌路彼此 2018-07-30 05:24:32
package lianxi1;
import java.util.*;
public class SY3 {
public SY3()
{
List list=new ArrayList();
list.add(1);
list.add(10);
list.add(5);
list.add(7);
list.add(6);
list.add(2);
list.add(9);
list.add(20);
list.add(14);
list.add(35);
System.out.println("原序列:");
for(int i=0;i<=list.size()-1;i++)
{
System.out.println(list.get(i));
}
System.out.println("新序列升序");
Collection.sort(list);
for(int i=0;i<list.size()-1;i++)
{
System.out.println(list.get(i));
}
System.out.println("新序列降序");
Collection.reverse(list);

for(int i=0;i<=list.size()-1;i++)
{
System.out.println(list.get(i));
}
}

public static void main(String[] args)
{
// TODO Auto-generated method stub
new SY3();

}

}
程序中sort和reverse好像有错误,不知道怎么修改
错误显示为:Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method sort(List) is undefined for the type Collection
The method reverse(List) is undefined for the type Collection

at lianxi1.SY3.<init>(SY3.java:23)
at lianxi1.SY3.main(SY3.java:40)
...全文
170 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
java-小学生 2018-07-30
  • 打赏
  • 举报
回复
The method sort(List) is undefined for the type Collection
The method reverse(List) is undefined for the type Collection

写的很清楚 没有这两个方法 应该是 Collections.sort();

51,408

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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