import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Collection;
public class ClearlyAnArrayList
{
public static void main(String[] args){
Scanner kb=new Scanner(System.in);
ArrayList<Integer>ints=new ArrayList<Integer>();
int num=kb.nextInt();
while(num!=-1){
ints.add(num);
}
sortPrint(ints);
}
public static void sortPrint(Collection<Integer>ints){
Collections.sort(ints);
for(Integer i:ints){
System.out.printf("%d\n",i);
}
}
}
这是我用 blueJ 编译的代码 当我编译它时,我得到一个冗长的错误,它以“
no suitable method for sort(java.util.Collection<java.lang.Integer>)
”开头,然后继续说更多我不明白的东西。
对此的解决方案是我使用的 List 不是一个集合,并且Collections.sort()
需要一个 List
对于我的所有实用程序,还有比单数
import
陈述更好的方法吗?
给出的解决方案是
import java.util.*;