Reputation: 308
I am looping through some strings and i want to add each string to the appropriate set using java treeset.How can i check if treeset exists?My code should look similiar to this:
if (set exists)
set.add(string)
else{
TreeSet<Integer> tree = new TreeSet<Integer>();
tree.add(string)
}
Upvotes: 0
Views: 355
Reputation: 777
Somewher in your code you will have a variable called set
of type TreeSet or Set
if (set != null ){
set.add(string)
}else{
set = new TreeSet<String>(); // it's not set if integers but Strings
tree.add(string)
}
Upvotes: 3