• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Need replacement help for HashTable  RSS feed

 
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
 
author
Posts: 23832
140
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
 
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
 
Java Cowboy
Posts: 16084
88
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
Boost this thread!