英文:
Trying to sort a Double Collection
问题
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.
英文:
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.
答案1
得分: 2
你必须像这样声明变量:
List<Double> csvData = new ArrayList<Double>();
错误很明显:Collections.sort()
方法需要一个 List
对象,Collection
是不起作用的。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论