Menu
Question Index
...

What will be the output of the following program?

import java.util.*;

public class TestLinkedHashSet
{
    public static void main(String[] args)
    {
        LinkedHashSet lhashSet = new LinkedHashSet<String>();
        lhashSet.add(new Integer("1"));
        lhashSet.add(new Integer("2"));
        lhashSet.add(new Integer("3"));
        lhashSet.add(new Integer("3"));
        lhashSet.add(new Integer("4"));
        lhashSet.add(new Integer("5"));
        lhashSet.add(new Integer("5"));
        lhashSet.add(new Integer("5"));
        lhashSet.add(new Integer("10"));
        Object[] objArray = lhashSet.toArray();
        Arrays.sort(objArray);
        for (Object element : objArray)
            System.out.print(element + " ");
    }
}


1 10 2 3 4 5
1 2 3 4 5 10
1 2 3 3 4 5 5 5 10
1 10 2 3 3 4 5 5 5
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