Math, asked by malavika322000, 7 months ago

What will happen when the following code is executed?
import java.util. :
public class Test6 {
public static void main(String args[]) {
SortedSet s = new TreeSet();
s.add(new String("Red"));
s.add(new String("White"));

s.add(new String("Blue"));
System.out.println(s.first();
}​

Answers

Answered by SamikshaDhere
0

Answer:

The above code will execute as :

Step-by-step explanation:

The given code is in Java language.

The correct code with proper indentations is :

import java.util.*;

public class Test {

   

 public static void main(String[] args) {

   LinkedHashSet<String> set1 = new LinkedHashSet<>();

   set1.add("New York");

   LinkedHashSet<String> set2 = set1;

   LinkedHashSet<String> set3 =

     (LinkedHashSet<String>)(set1.clone());

     

   set1.add("Atlanta");

   System.out.println("set1 is " + set1);

   System.out.println("set2 is " + set2);

   System.out.println("set3 is " + set3);

   set1. forEach (e -> System. out. print (e + " ")) ;

   

 }

 

}

The output of the above code is in the form of :

set1 is [New York, Atlanta]

set2 is [New York, Atlanta]

set3 is [New York]

New York Atlanta

#SPJ2

Similar questions