Java Program to show TreeSet Demo

Simple java program to show treesetDemo… I m not sure about the program. Check it for yourself… Hopefully it’s correct.

import java.io.*;
import java.util.*;
class TreesetDemo
{
public static void main(String arg[]) throws IOException
{
TreeSet s1=new TreeSet();
InputStreamReader in=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(in);
int i;
System.out.println(“nEnter the number of item to be put on the tree:”);
int n=Integer.parseInt(br.readLine());
String s=null;
for(i=1;i<=n;i++)
{
System.out.println(“n Enter the  ” +i+ ” character:”);
s=br.readLine();
s1.add(s);
}
System.out.println(“nThe item on the tree are:” +s1);
System.out.println(“nThe first element of the tree is:” +s1.first());
System.out.println(“nThe last element of the tree is:” +s1.last());
System.out.println(“nThe total number of element of the tree are:” +s1.size());
System.out.println(“nEnter the  element to be removed:  “);
String rm=br.readLine();
s1.remove(rm);
System.out.println(“nThe item on the tree are:” +s1);
}
}

Add Comment