In: Computer Science
Write a program that reads a line of text input by the user and places each word in a TreeSet. Print the elements of the TreeSet to the screen. This will cause the elements to be printed in ascending order.
Using Eclipse for this.
TreeSetUse.java.
import java.util.Scanner;
import java.util.TreeSet;
public class TreeSetUse {
   public static void main(String[] args) {
       Scanner sc = new
Scanner(System.in);
       TreeSet<String> tree = new
TreeSet<String>();
       //reading the line
       System.out.println("Enter line:
");
       String str = sc.nextLine();
       //spliting into words and adding to
tree
       for (String s : str.split("
"))
          
tree.add(s);
       //printing TreeSet
       System.out.println(tree);
   }
}

Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me