Results 1 to 3 of 3
Thread: Help Tree Set
- 10-29-2009, 07:54 AM #1
Member
- Join Date
- Oct 2009
- Posts
- 1
- Rep Power
- 0
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???
- 10-29-2009, 08:26 AM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,568
- Rep Power
- 15
As suggested at Daniweb, try using trim on the Strings before adding them to the sets.
- 10-29-2009, 11:45 AM #3
Member
- Join Date
- Oct 2009
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
how to select the whole tree
By beatme in forum XMLReplies: 0Last Post: 10-10-2009, 07:01 PM -
Creating a Tree and then saving the Tree
By jackmatt2 in forum New To JavaReplies: 0Last Post: 08-22-2009, 01:51 PM -
B tree
By wide in forum New To JavaReplies: 2Last Post: 07-01-2009, 12:37 AM -
AVL-tree construction
By student89 in forum Advanced JavaReplies: 0Last Post: 10-27-2008, 06:33 AM -
Need Help With Tree Adt
By avi in forum New To JavaReplies: 0Last Post: 03-20-2008, 04:11 AM
Bookmarks