Return type from a Comparator

前端 未结 6 1384
暖寄归人
暖寄归人 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 16:04

    Depending on how you want to sort based on this comparator you need to place some logic in the comparator. Your comparator only returns 0 which means equal

    class MyComparator implements Comparator {
    
        public int compare(Object o1, Object o2) {
            // TODO Auto-generated method stub
            return o1.compareTo(o2);
        }
    }
    

提交回复
热议问题