尝试对 Double Collection 进行排序

Trying to sort a Double Collection

我正在尝试对 Collection 进行排序。我似乎无法让我的代码与我在网上找到的内容一起工作。

Collection:

[104.131119, 104.188937, 93.174548, 100.533096, 97.902247, 98.608619, 93.380054, 106.690206, 106.461181, 108.190245]

代码:

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>

如有任何帮助,我们将不胜感激。

您必须像这样声明变量:

List<Double> csvData = new ArrayList<Double>();

错误很明显:Collections.sort() 方法需要一个 List 对象,Collection 将不起作用。