Results 1 to 8 of 8

Thread: HashSet

  1. #1
    Dayanand is offline Member
    Join Date
    Feb 2011
    Posts
    61
    Rep Power
    0

    Default HashSet

    package firstDay;

    import java.util.HashSet;

    public class HashSet2
    {
    public static void main(String[] args)
    {
    HashSet hs = new HashSet();
    hs.add(90);
    hs.add("d90");
    hs.add("90d");
    hs.add(90.0);
    hs.add("dayanand");
    hs.add("shwetha");
    hs.add("annonmyous");
    System.out.println(hs);
    }
    }
    hi
    in the above program the statement hs.add(90); can be modified to
    1. hs.add(90d);
    2. hs.add(90f);
    3. hs.add(90l);

    My doubts
    but when i try other than d,f,l i got an error y it so.?
    is there any logic.?

    the statement hs.add("shwetha"); results in the first position
    i.e the output is[shwetha, d90, 90.0, annonmyous, dayanand, 90d, 90]
    why shwetha occuiped first place in the array when dayanand,annonmyous is there in the hs
    whats the logic over here.?

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    I believe it has somethig to do with hash sets store and get information. Check out the API and google about them to see how all that is handled. Also, what kind of error does part 1 give you?

  3. #3
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    299
    Rep Power
    4

    Default

    d is for double, l is for long and f is for float those are all numbers, in other way you should put for example "90a" as it is string.

  4. #4
    Dayanand is offline Member
    Join Date
    Feb 2011
    Posts
    61
    Rep Power
    0

    Default

    Quote Originally Posted by sunde887 View Post
    I believe it has somethig to do with hash sets store and get information. Check out the API and google about them to see how all that is handled. Also, what kind of error does part 1 give you?
    if the satement is hs.add(90a);, i got Syntax error on token "a", delete this token

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    hs.add(90), what error does this put up? Appendage l,d, and f all are numbers as pointed out by milovan, a doesn't represent a number. Does adding 90 work?

  6. #6
    Dayanand is offline Member
    Join Date
    Feb 2011
    Posts
    61
    Rep Power
    0

    Default

    Quote Originally Posted by sunde887 View Post
    hs.add(90), what error does this put up? Appendage l,d, and f all are numbers as pointed out by milovan, a doesn't represent a number. Does adding 90 work?
    what is milovan.?

  7. #7
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    A poster who posted after me in this thread.

  8. #8
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    299
    Rep Power
    4

    Default

    what is milovan.?
    Interactive software solutions perhaps:D

Similar Threads

  1. HashSet with array
    By pi4r0n in forum New To Java
    Replies: 4
    Last Post: 03-10-2011, 11:20 PM
  2. Getting value for key in HashSet
    By Venny in forum New To Java
    Replies: 12
    Last Post: 02-02-2011, 08:42 AM
  3. Adding to a HashSet
    By Neivaed in forum New To Java
    Replies: 6
    Last Post: 12-05-2010, 06:16 PM
  4. :( anyone here plz help on HashSet
    By waklo99 in forum New To Java
    Replies: 8
    Last Post: 09-20-2010, 03:02 AM
  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
  •