Results 1 to 2 of 2

Thread: Java HashSets

  1. #1
    sameerr_007 is offline Member
    Join Date
    Mar 2011
    Rep Power

    Default Java HashSets

    Hello Everybody,
    I am using HashSets in my program to maintain hash values.
    My problem is: it works fine when i add a value in this HashSet, it works fine but

    HashSet hsh = new HashSet();
    if((hsh.contains("John") == true)

    Here the output is Success...
    BUT when i restart this program and directly say hsh.contains("John");
    It gives me Unsuccessful as output...

    In short i want to make hashSets such that once an element is added should remain persistent... Hope you got my question...

  2. #2
    lovelesh is offline Senior Member
    Join Date
    Nov 2010
    Blog Entries
    Rep Power


    Hi Sameer,

    The problem in the code is - you are not persisting the hashset after adding elements to it. So as soon as you stop the application, your whole data vanishes.

    Solution:- Persist the hashset on local file system before application quits. Then read (deserialize) the persisted file and start using it.

    May be you can use shutdown hook for serialization purpose.

Similar Threads

  1. Java HashSets
    By sameerr_007 in forum New To Java
    Replies: 5
    Last Post: 03-09-2011, 12:30 PM
  2. help using hashsets?
    By yasmin k in forum New To Java
    Replies: 1
    Last Post: 04-17-2010, 11:09 PM
  3. HashSets
    By DavidG24 in forum New To Java
    Replies: 5
    Last Post: 04-19-2009, 07:02 PM
  4. how does the remove method work for sets and hashsets
    By haridharna in forum Advanced Java
    Replies: 4
    Last Post: 08-06-2007, 01:48 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