Skip to main content

We can implement different sort orders with the Comparator interface’s compare() method, and pass the Comparator as a parameter to List.sort(). Does anyone know what sorting algorithm the Comparator Interface uses or will we be able to implement any of the sorting algorithms as per our need?

Since it looks like it is using the bubble sort  from the example given here:

https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_System_Comparator.htm#apex_interface_System_Comparator_Example

답변 9개
  1. 2023년 12월 26일 오후 3:12

    As you implement the interface, you can design your own sort algorithm.  That's the beauty of the implementation of the Interface. 

     

    However, if using the List/Collection default sort method, it should be based on Java logic, which would be Mergesort.

0/9000