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
lengthy error which starts off “no suitable method for” and then goes on to
sort(java.util.Collection<java.lang.Integer>)
say more stuff I don’t understand.
The solution to this was that I was using a List which is not a collection and Collections.sort() expects a List
Also is there a better way than singular
importstatements for all
my utils?
The solution given was
import java.util.*;
Collections.sortexpects aListand notCollection, so change yoursortPrintmethodFrom
To
Offtopic:
Instead of working directly on concrete classes program to an interface.
Prefer
Over