Menu
Question Index
...

What will be the output of the following program?

import java.util.*;

public class SortingArrayList
{
    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("1");
        list.add("22");
        list.add("9");
        list.add("6");
        list.add("4");
        list.add("4");
        list.add("8");
        list.add("4");
        list.add("4");
        copyList.addAll(list);
        Collections.sort(copyList);
        Collections.reverse(list);
        System.out.println(list);
        System.out.println(copyList);
    }
}


[4, 4, 8, 4, 4, 6, 9, 22, 1, 5, 7, 11, 3, 10, 2]
[1, 10, 11, 2, 22, 3, 4, 4, 4, 4, 5, 6, 7, 8, 9]
[4, 4, 8, 4, 4, 6, 9, 22, 1, 5, 7, 11, 3, 10, 2]
[1, 2, 3, 4, 4, 4, 4, 5, 6, 7, 8, 9, 10, 11, 22]
[2, 10, 3, 11, 7, 5, 1, 22, 9, 6, 4, 4, 8, 4, 4]
[1, 2, 3, 4, 4, 4, 4, 5, 6, 7, 8, 9, 10, 11, 22]
[2, 10, 3, 11, 7, 5, 1, 22, 9, 6, 4, 4, 8, 4, 4]
[1, 10, 11, 2, 22, 3, 4, 4, 4, 4, 5, 6, 7, 8, 9]
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