• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need replacement help for HashTable

 
Milton Singh
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21490
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 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
 
Anuraag Godika
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Extend the HashTable class with your own and override the put method to accept only known keys ??
 
Milton Singh
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15480
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic