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...
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.