Results 1 to 3 of 3
  1. #1
    truant420 is offline Member
    Join Date
    Dec 2010
    Rep Power

    Question bluej hashset problem ;s

    alright, i'm stuck on this part of my project and i really tried to get over it but nothing seems to get better...
    My aim is to add a number of objects to a HashSet with a for-loop but i can't seem to accomplish that. The size of the HashSet stubbornly stays null. Here is the code:

    * Constructor for objects of class Pocket
    public Pocket()
    // initialise instance variables
    HashSet<Object> Object = new HashSet<Object>();
    for(int i=0; i<20; i++) {
    Object.add(new Object());

    I might be missing something crucial here and call me a retard but i really cant see what it is so any help would be appreciated.
    Thanks in advance :)

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power


    How are you checking the size of the hash set?

    Oh, and Object is not a good name for a variable. Variables should start with a lower case so you don't end up with variables being the same name as classes.

  3. #3
    truant420 is offline Member
    Join Date
    Dec 2010
    Rep Power

Similar Threads

  1. :( anyone here plz help on HashSet
    By waklo99 in forum New To Java
    Replies: 8
    Last Post: 09-20-2010, 03:02 AM
  2. Hashset and Custom Objects problem! Wont add! :(
    By maz09 in forum New To Java
    Replies: 4
    Last Post: 03-20-2010, 03:22 AM
  3. HashSet Contains problem
    By guywalder in forum Advanced Java
    Replies: 11
    Last Post: 09-01-2009, 02:48 PM
  4. HashSet anomaly
    By jon80 in forum New To Java
    Replies: 1
    Last Post: 06-21-2009, 08:22 PM
  5. Iterating through a HashSet
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-21-2008, 04:34 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