File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Need replacement  help for HashTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need replacement  help for HashTable" Watch "Need replacement  help for HashTable" New topic
Author

Need replacement help for HashTable

Milton Singh
Greenhorn

Joined: Mar 27, 2008
Posts: 5
I need a replacement for HashTable in my design.
Restriction:
> can use only vector, properties,hashtable

Issue:

> I have a util class where we are using hashtable h1 as parameter in method1.
> this util class will be used by a number of users.
> the users will set the values in h1 and will call method1 (h1 as param).
> The keys for h1 has been defined in util class and I am expecting the users to use the same key
> But in real use case the users can define their own key and in that case in util class we will get null value which will disrupt the processing of method 1

Please think of it and give suggestions. I will update your queries
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18754
    
  40

> can use only vector, properties,hashtable


So, you want to replace HashTable with either a Vector or Properties? Well, neither of these two classes are good replacements for HashTable -- as Vector doesn't have keys, and you don't need the file support of the Properties class.

> But in real use case the users can define their own key and in that case in util class we will get null value which will disrupt the processing of method 1


Well, you could put more validity checks in method1() to make sure that the parameters (key-values) are valid. Generally, public methods should do this anyway.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Anuraag Godika
Greenhorn

Joined: Sep 17, 2008
Posts: 2
Extend the HashTable class with your own and override the put method to accept only known keys ??
Milton Singh
Greenhorn

Joined: Mar 27, 2008
Posts: 5
Originally posted by Anuraag Godika:
Extend the HashTable class with your own and override the put method to accept only known keys ??


Thank You guys for your inputs. I will try to create a subclass for hashtable and will see how it works
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

Is this about the SCJP exam? I'll move this to a more appropriate forum. Follow the link at the top of the page to continue.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Need replacement help for HashTable