treeset question
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Robert_Taylor
Posted On:   Thursday, February 1, 2007 03:09 PM

I have a treeset that can have the following values [0,1,3,4,5,6,7,8,9]
if there is a 7 I need to remove this value from the treeset and keep all the rest of the values. is there a way to do this??

Re: treeset question

Posted By:   vikas_patel  
Posted On:   Saturday, February 24, 2007 02:27 AM

u can delete this value by using
in jdk1.5
set.remove(7);

Re: treeset question

Posted By:   Robert_Taylor  
Posted On:   Thursday, February 1, 2007 06:01 PM

here is the code that I have come up with. Let me know if anybody has a better way of doing this. Thanks


if (copyFrom.getvalue().contains(new Integer (7))){
Iterator iter = copyFrom.getvalue().iterator();
while (iter.hasNext()) {

if (newvalue.contains(new Integer (7))){
newvalue.remove(new Integer (7));
}
else{
newvalue.add(iter.next());
}
}
copyTo.setvalue(new TreeSet(newvalue));
About | Sitemap | Contact