Home  >  Q&A  >  body text

java排序

有一个数组
[10-20,41-50,31-40,51-60,21-30],使他按照10-20,21-30,...的顺序排序有什么高效的方法吗?谢谢

天蓬老师天蓬老师2743 days ago565

reply all(6)I'll reply

  • PHPz

    PHPz2017-04-18 10:54:58

    If there are only a few array elements, there will be no big difference in whichever sorting method you use.
    Sorting algorithms can only show their respective advantages when the amount of data is relatively large.

    reply
    0
  • 迷茫

    迷茫2017-04-18 10:54:58

    For sorting, there are many classic sorting algorithms. Just change the size comparison method to your own and it will be ok.

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-18 10:54:58

    Rewrite the compareTo method, remove the ‘-’ in the middle and convert it to an int comparison number

    reply
    0
  • 怪我咯

    怪我咯2017-04-18 10:54:58

    What do you mean? Two-dimensional array?

    reply
    0
  • 高洛峰

    高洛峰2017-04-18 10:54:58

    (1) Apply Collections framework: implement the comparator interface and rewrite the compare method in it.
    (2) Override the CompareTo method under String type

    reply
    0
  • 怪我咯

    怪我咯2017-04-18 10:54:58

    When sorting, calculate the absolute value of the elements, and then choose different sorting methods according to the number of elements

    reply
    0
  • Cancelreply