Results 1 to 7 of 7

Thread: treeset compare

  1. #1
    samaravadhi is offline Member
    Join Date
    Sep 2011
    Posts
    5
    Rep Power
    0

    Default 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

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,987
    Rep Power
    9

    Default 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!

  3. #3
    samaravadhi is offline Member
    Join Date
    Sep 2011
    Posts
    5
    Rep Power
    0

    Default Re: treeset compare

    I have tried using iterator

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,987
    Rep Power
    9

    Default Re: treeset compare

    Quote Originally Posted by samaravadhi View Post
    I have tried using iterator
    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!

  5. #5
    samaravadhi is offline Member
    Join Date
    Sep 2011
    Posts
    5
    Rep Power
    0

    Default 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;
    }

    }

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default 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.

    -----

    Java Code:
    if((stn.compareToIgnoreCase(sts)== 0 ){
    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).

  7. #7
    samaravadhi is offline Member
    Join Date
    Sep 2011
    Posts
    5
    Rep Power
    0

Similar Threads

  1. bug? list and treeSet
    By douglas.nelson@oracle.com in forum Advanced Java
    Replies: 34
    Last Post: 04-10-2011, 11:30 PM
  2. TreeSet weirdness
    By Bulska in forum New To Java
    Replies: 3
    Last Post: 03-18-2011, 03:29 PM
  3. problems with a TreeSet
    By j2me64 in forum Advanced Java
    Replies: 1
    Last Post: 01-10-2011, 03:40 PM
  4. Please Help - TreeSet
    By Riftara in forum New To Java
    Replies: 1
    Last Post: 10-21-2010, 08:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •