【问题标题】:Trying to use Collections.sort to sort my array with no luck尝试使用 Collections.sort 对我的数组进行排序但没有运气
【发布时间】:2018-11-17 02:14:27
【问题描述】:

我已经在下面创建了数组,但没有运气对其进行排序

String[] albums = {"Abbey Road - Beatles","Thriller - Michael Jackson",
    "Queen - News of the World","Gimme Shelter - The Rolling Stones",
    "Pink Floyd - The Dark Side of the Moon"};

使用 Collections.sort(albums);给出错误:没有合适的方法用于 sort(String[])

我已经导入了 java.util.*;但是这个错误仍然存​​在

我仍在学习,不明白如何解决这个问题或我缺少什么

【问题讨论】:

    标签: java arrays sorting compiler-errors


    【解决方案1】:

    你有一个数组(不是Collection)。您可以使用Arrays.sort(T[], Comparator<? super T>) 对其进行排序。喜欢,

    Arrays.sort(albums, Comparator.naturalOrder());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-03
      • 2010-12-03
      相关资源
      最近更新 更多