Results 1 to 7 of 7
Thread: treeset compare
- 09-06-2011, 08:21 PM #1
Member
- Join Date
- Sep 2011
- Posts
- 5
- Rep Power
- 0
treeset compare
I have two treesets ‘ts’ and ‘tn’.
I have to compare ts with tn if value in ts is there and not in tn then I have to print ts value not found in tn.
Also if value in tn is there and not in ts , I have to print tn value not in ts…
Can you suggest me how to compare two treeset…
both treesets have string values
- 09-06-2011, 08:23 PM #2
Re: treeset compare
What have you tried? What did the API tell you?
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 09-06-2011, 08:24 PM #3
Member
- Join Date
- Sep 2011
- Posts
- 5
- Rep Power
- 0
Re: treeset compare
I have tried using iterator
- 09-06-2011, 08:31 PM #4
Re: treeset compare
How'd you use it? What happened when you tried that? Where's your SSCCE?
Recommended reading: TreeSet (Java Platform SE 6)How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 09-06-2011, 09:02 PM #5
Member
- Join Date
- Sep 2011
- Posts
- 5
- Rep Power
- 0
Re: treeset compare
TreeSet ts= c1.readPropertiesFile(F1);
TreeSet tn= c1.readPropertiesFile(F2);
Iterator itn = tn.iterator();
Iterator its= ts.iterator();
while (itn.hasNext()){
String stn=(String)itn.next();
System.out.println(" ");
// System.out.println("Stn:"+ stn + " ");
while (its.hasNext()){
String sts=(String)its.next();
if((stn.compareToIgnoreCase(sts) )== 0 ){
System.out.println("Sts:"+ sts + " ");
System.out.println("Stn:"+ stn + " ");
break;
}
}
- 09-06-2011, 11:34 PM #6
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,539
- Rep Power
- 11
Re: treeset compare
That's only a snippet of code and you didn't say what it does. Read the SSCCE link you were given earlier.
-----
This will be true when the two strings are equal - but you are trying to find strings in one set but not the other. The link to the javadocs is also very useful here. Look for the removeAll() method which is designed to find elements in one set but not in another set (or collection).Java Code:if((stn.compareToIgnoreCase(sts)== 0 ){
- 09-07-2011, 03:59 PM #7
Member
- Join Date
- Sep 2011
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
bug? list and treeSet
By douglas.nelson@oracle.com in forum Advanced JavaReplies: 34Last Post: 04-10-2011, 11:30 PM -
TreeSet weirdness
By Bulska in forum New To JavaReplies: 3Last Post: 03-18-2011, 03:29 PM -
problems with a TreeSet
By j2me64 in forum Advanced JavaReplies: 1Last Post: 01-10-2011, 03:40 PM -
Please Help - TreeSet
By Riftara in forum New To JavaReplies: 1Last Post: 10-21-2010, 08:33 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks