I am trying to sort a Collection. I cant seem to get my code to work with what I have found online.
Collection:
[104.131119, 104.188937, 93.174548, 100.533096, 97.902247, 98.608619, 93.380054, 106.690206, 106.461181, 108.190245]
Code:
Collection<Double> csvData = new ArrayList<Double>(); //logic of reading csv file and adding data to collection //Adding into the collection using csvData.add(csvValue); //sorting Collections.sort(csvData); // error, The method sort(List<T>) in the type Collections is not applicable for the arguments (Collection<Double>
Any help would be appreciated.
Advertisement
Answer
You must declare the variable like this:
List<Double> csvData = new ArrayList<Double>();
The error is clear: the Collections.sort()
method expects a List
object, a Collection
won’t work.