Menu
Question Index
...

What will be the output of the following program?

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


1 2 3 4 5
1 2 3 3 4 5 5 5
1 2 3 3 5 4 5 5
Compilation Error
Runtime Error

Doubts

Problems

Topic: Java LinkedHashSet

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App