Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

half printing HashSet

 
Tony Cossie
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,
I'm having a problem with printing out a HashSet, it reads in 10,000 words - compares it with another HashSet of 10,000 words but only prints out 5,000 results words! It should print out 10,000. I'm using a bufferedReader to read in the information,
any ideas?
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A HashSet can't contain duplicate entires, you can't add the same element more than once (well you can add it as many times as you want but it will only be stored once). Is that in anyway related to your problem?
 
Tony Cossie
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know that, that's the main reason behind me using a HashSet because all the elements in it are unique.
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. A couple more ideas.
Can you try and reproduce your problem with a different size of input. Or to say it another way; do you get the same problem if for example your input is 100 (instead of 10,000)? Do you only print out 50?
HashSet seems to have a "size" method. How big does this method say your HashSet is?
 
Tony Cossie
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, i've tried it with values from 10 to 10000 (in increments of 100) and it will only print out 1/2 the list. I tried setting the size of the HashSet -
HashSet set1 = new HashSet(10000);
But have had no joy. I'm stuck for ideas as to why this keeps occurring!
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you say "size" what is it telling you? This may help you determine if the problem is loading the HashSet or printing the HashSet. If the "size" is the same as the number of entires which is being printed than the problem must be with loading the data. If the "size" is different than the number of items which are printed than the problem is with the printing.
I assume to print you are creating an iterator?
 
Tony Cossie
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I checked it again, the size is 10000 but when i put a counter inside the print loop, it returns with 5000.
I have no idea what's up!
I did a re-check again, i've found a problem with the method i wrote to "get" the Set, it was working for two sets and was splitting the HashSet between them!
Thanks for your help!
[This message has been edited by Tony Cossie (edited October 23, 2001).]
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad to hear that you found the problem.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic