import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
public class TreeSetToList {
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);
List<String> list = new ArrayList<String>(ts);
for (String str : list) {
System.out.println(" List Element is = "+str);
}
}
}
Output:
ts =[chandigarh, dehradun, delhi, kolkata, mumbai]
List Element is = chandigarh
List Element is = dehradun
List Element is = delhi
List Element is = kolkata
List Element is = mumbai
No comments:
Post a Comment