Menu
Question Index
...

Compare the following Programs?

import java.util.*;
public class SubWoofer1
{
    public static void main(String args[])
    {
        Set<String> hashSet = new HashSet<String>(Arrays.asList(new String[] {"a", "b", "c", "d", "e", "e"}));
        System.out.println(hashSet);
    }
}

import java.util.*;
public class SubWoofer2
{
    public static void main(String args[])
    {
        String[] strs = new String[] {"a", "b", "c", "d", "e"};
        Set<String> hashSet = new HashSet<String>(Arrays.asList(strs, "e"));
        System.out.println(hashSet);
    }
}


Both SubWoofer1 and SubWoofer2 produce same output.
SubWoofer1 and SubWoofer2 produce different output.
SubWoofer2 compiles and runs with out any error, but SubWoofer1 gives compilation error.
SubWoofer1 compiles and runs with out any error, but SubWoofer2 gives compilation error.
Both SubWoofer1 and SubWoofer2 fail to execute.

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