Return type from a Comparator

前端 未结 6 1376
暖寄归人
暖寄归人 2020-12-09 15:16

What does the return value inside the Comparator actually mean?

For example :

class TreeSetDemo
{
    public static void main(String         


        
6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-09 15:58

    It's about sort algorithm which needs compare.

    Correct:

    class MyComparator implements Comparator {
        public int compare(Integer o1, Integer o2) {
            // Calling the Integer class's compareTo method
            return o1.compareTo(o2);
        }
    }
    

提交回复
热议问题