Menu
Question Index
...

What will be the output of the following program?

import java.util.*;

public class Hp7540
{
    public static void main(String[] args)
    {
        List<String> list = new ArrayList<String>();
        List<String> copyList = new ArrayList<String>();
        list.add("2");
        list.add("10");
        list.add("3");
        list.add("11");
        list.add("7");
        list.add("5");
        list.add("4");
        list.add("1");
        list.add("22");
        list.add("9");
        list.add("6");
        list.add("4");
        list.add("8");
        list.add("4");
        list.add("4");
        copyList.addAll(list);
        Collections.sort(copyList);
        Collections.reverse(list);
        for (int index = 0; index < 14; index++)
            if (list.get(index) != copyList.get(index))
                System.out.print(list.get(index) + " ");
    }
}


4 4 8 4 6 9 22 1 5 7 11 3 10 2
4 4 8 6 9 22 1 4 5 7 11 3 10 2
4 4 8 6 9 22 1 4 5 7 11 3 10
4 4 8 4 6 9 22 1 5 7 11 3 10
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java Collection Algorithms

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App