美文网首页Data Structures -- Java
usage of comparator in Java

usage of comparator in Java

作者: Leahlijuan | 来源:发表于2019-10-20 07:37 被阅读0次

1

int[][] nums = new int[][]{{1,2,3},{4,5,6}}; 
Arrays.sort(nums, (a,b)->(a[0]-b[0]));

Queue<Integer> maxHeap = new PriorityQueue<>((a1, a2) -> (a2 - a1));

2

Map<int[], Integer> map = new TreeMap<>(new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                if (o1[1] < o2[1]) {
                    return -1;
                }
                return 1;
            }
        });

相关文章

网友评论

    本文标题:usage of comparator in Java

    本文链接:https://www.haomeiwen.com/subject/ndsomctx.html