Menu
Question Index
...

What will be the output of the following program?

import java.util.*;

public class NumbersCanBeConfusing {

    public static void main(String[] args) {
        String[] runs = {"two", "four", "one", "six", "two", "six", "zero", "four", "one", "two", "zero", "zero"};
        List<String> list = new ArrayList<String>();
        list.addAll(new HashSet<String>(Arrays.asList(runs)));
        Collections.sort(list);
        list.set(3, "three");
        list.addAll(list.subList(1, list.size() - 1));
        list.remove(2);
        list.add(1, "six");
        System.out.println(list);
    }
}


[four, six, four, three, six, six, two, two, two, zero, zero, zero, four, one, three, six, six, two, two, two, zero, zero]
[four, six, one, three, zero, one, six, three]
[four, six, one, six, three, zero, one, six, three]
Some other output or 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