wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes half printing HashSet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "half printing HashSet" Watch "half printing HashSet" New topic
Author

half printing HashSet

Tony Cossie
Greenhorn

Joined: Mar 11, 2001
Posts: 13
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

Joined: Mar 16, 2001
Posts: 986

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?


Please ignore post, I have no idea what I am talking about.
Tony Cossie
Greenhorn

Joined: Mar 11, 2001
Posts: 13
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

Joined: Mar 16, 2001
Posts: 986

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

Joined: Mar 11, 2001
Posts: 13
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

Joined: Mar 16, 2001
Posts: 986

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

Joined: Mar 11, 2001
Posts: 13
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

Joined: Mar 16, 2001
Posts: 986

Glad to hear that you found the problem.
 
GeeCON Prague 2014
 
subject: half printing HashSet