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);
}
}
}
This is the code I'm compiling with blueJ. When I compile it, I get a long error starting with " no suitable method for
sort(java.util.Collection<java.lang.Integer>)", and then continue to say more things that I donβt understand.
The solution to this was that I used a list that is not a collection but Collections.sort()expects a list
Also is there a better way than singular expressions importfor all my utilities?
The decision was
import java.util.*;
source
share