Results 1 to 3 of 3

Thread: Help Tree Set

  1. #1
    ShuiYinDeng is offline Member
    Join Date
    Oct 2009
    Posts
    1
    Rep Power
    0

    Default Help Tree Set

    oldAccount text file is Nicholas, Diana, Eric,Andy, Alex , AMy
    CurrentAccount text file is Andy Alex Amy Kelvin cherry Betty
    import java.util.*;
    import java.io.*;

    public class Example2
    {
    public static void main(String[]args) throws IOException
    {
    System.out.print (" Old Account is: ");
    System.out.println();
    TreeSet<String> oldAcc = new TreeSet<String>();
    Scanner oldacc = new Scanner(new FileReader("OldAccount.txt"));
    while (oldacc.hasNext()) {
    String Line =oldacc.nextLine();
    oldAcc.add(Line);
    }
    System.out.println(oldAcc);
    oldacc.close();

    System.out.print (" Current Account is: ");
    System.out.println();
    TreeSet<String> CurrAcc = new TreeSet<String>();
    Scanner curracc = new Scanner(new FileReader("CurrentAccount.txt"));
    while (curracc.hasNext()) {
    String Line1 =curracc.nextLine();
    CurrAcc.add(Line1);

    }
    System.out.println(CurrAcc);
    curracc.close();


    TreeSet<String> GradAcc = new TreeSet<String>();

    GradAcc.addAll(oldAcc);
    GradAcc.removeAll(CurrAcc);
    System.out.print("The Grad Account is " + GradAcc);

    }
    }


    The out put of GradAcc should is Diana , Eric , Nicholas
    But My output is Alex ,Andy , Diana , Eric , Nicholas

    any solution to solve???

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    As suggested at Daniweb, try using trim on the Strings before adding them to the sets.

  3. #3
    Join Date
    Oct 2009
    Posts
    3
    Rep Power
    0

    Default

    First you need to split the input line from the file into strings, and add the strings to the Treeset...

Similar Threads

  1. how to select the whole tree
    By beatme in forum XML
    Replies: 0
    Last Post: 10-10-2009, 06:01 PM
  2. Creating a Tree and then saving the Tree
    By jackmatt2 in forum New To Java
    Replies: 0
    Last Post: 08-22-2009, 12:51 PM
  3. B tree
    By wide in forum New To Java
    Replies: 2
    Last Post: 06-30-2009, 11:37 PM
  4. AVL-tree construction
    By student89 in forum Advanced Java
    Replies: 0
    Last Post: 10-27-2008, 05:33 AM
  5. Need Help With Tree Adt
    By avi in forum New To Java
    Replies: 0
    Last Post: 03-20-2008, 03:11 AM

Posting Permissions

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