package com.javapro.treeset;
import java.util.Set;
import java.util.TreeSet;
public class CreateTreeSet {
public static void main(String[] args) {
Set<String> ts = new TreeSet<String>();
ts.add("mumbai");
ts.add("delhi");
ts.add("kolkata");
ts.add("chandigarh");
ts.add("dehradun");
// print treeset
System.out.println(" ts ="+ts);
}
}
Output:
ts =[chandigarh, dehradun, delhi, kolkata, mumbai]
import java.util.Set;
import java.util.TreeSet;
public class CreateTreeSet {
public static void main(String[] args) {
Set<String> ts = new TreeSet<String>();
ts.add("mumbai");
ts.add("delhi");
ts.add("kolkata");
ts.add("chandigarh");
ts.add("dehradun");
// print treeset
System.out.println(" ts ="+ts);
}
}
Output:
ts =[chandigarh, dehradun, delhi, kolkata, mumbai]
No comments:
Post a Comment