尝试对双精度数集进行排序

huangapple go评论60阅读模式
英文:

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&lt;Double&gt; csvData = new ArrayList&lt;Double&gt;();

//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&lt;T&gt;) in the type Collections is not applicable for the arguments (Collection&lt;Double&gt;

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&lt;Double&gt; csvData = new ArrayList&lt;Double&gt;();

The error is clear: the Collections.sort() method expects a List object, a Collection won't work.

huangapple
  • 本文由 发表于 2020年9月11日 05:45:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/63838088.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定