Output elements

Report a typo

Here's a set of strings.

Set<String> nameSet = new TreeSet<>(Arrays.asList("Mr.Green", "Mr.Yellow", "Mr.Red"));

Output each of its elements with the loop with a new line.

Sample Input 1:

Sample Output 1:

Mr.Green
Mr.Red
Mr.Yellow
Write a program in Java 17
import java.util.*;

public class Main {

public static void main(String[] args) {
Set<String> nameSet = new TreeSet<>(Arrays.asList("Mr.Green", "Mr.Yellow", "Mr.Red"));
// write your code here
}
}
___

Create a free account to access the full topic