Menu
Question Index
...

What will be the output of the following program?

import java.util.*;
public class WorkOrNot {
    public static void main(String args[]) {
        Integer big = new Integer(2000000000);
        Integer small = new Integer(-2000000000);
        Integer zero = new Integer(0);
        Integer[] arr = new Integer[]{big, small, zero};
        Arrays.sort(arr, new Comparator() {
            public int compare(Object o1, Object o2) {
                int i1 = ((Integer) o1).intValue();
                int i2 = ((Integer) o2).intValue();
                return (i2 < i1 ? -1 : (i2 == i1 ? 0 : 1));
            }
        });
        System.out.println(Arrays.asList(arr));
    }
}


[-2000000000, 0, 2000000000]
[2000000000, 0, -2000000000]
[-2000000000, 2000000000, 0]
[0, 2000000000, -2000000000]
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: java.util.Arrays - Class Arrays In Collection Framework

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App