Question: Please solve it correctly if wrong i will give you dislike What will be the output when following code is executed? public static void main(String

Please solve it correctly if wrong i will give you dislike

What will be the output when following code is executed?

public static void main(String args[]) {

List list = new LinkedList ();

list. add("Earth");

list. add("Jupiter");

list. add ("Mars");

list. set(1, "Saturn");

list. add("Earth");

HashSet set = new MashSet();

set. addAll(list);

for (String element : set) {

System.out.print(element+" ");

}

}

Assumption:

1. All necessary configuration and imports are done

Note: The elements might appear in un-ordered fashion

a) Earth Mars Jupiter Saturn

b) Earth Mars Saturn

c) Saturn Jupiter Mars Earth

d) Saturn Jupiter Earth

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!