Collections.sort implementation

后端 未结 5 1828
灰色年华
灰色年华 2021-02-08 18:38

I can not understand the method implementation and the logic of Collections.sort method. Here is the method implementation i found,

public static 

        
5条回答
  •  感情败类
    2021-02-08 19:05

    First of all this method return type is void

    Because it's in-place implementation. List that passed to method will be sorted

    What is > does in the method signature?

    To compare results that extends Comparable interface for type T and it's children.

    Object[] a = list.toArray();

    Convert list to plain array.

    What is the purpose of using Array.sort here?

    Sorting of array.

    i.set((T)a[j]);

    assign to list elements in sorted order from array

提交回复
热议问题