greetings,

I would like to build a subset from a Hashtable. The subset is a Hashtable too. How could I do it? Is there any API out there?
Any advise or guideline are appreciated, thank you!
:rolleyes:

So a HashTable of HashTables?

no, I think he wants to return a part of a Hashtable based on some criterion related to the keys or values in it.
Hashtable doesn't have methods for that, it would be next to impossible to create a generic algorithm for it after all so Sun didn't bother.

It IS possible to write something for it yourself because you do know the specifics of your own data and how to extract the subset you want.

P.S. Don't use Hashtable unless you have a very good reason to. It's a legacy class only, HashMap is preferred and performs a lot better.

Thank you for advising... That address my problem very well :p I will try to implement my own methods.
However, my main concern is performance. Will it be too costly if I scan the value of each key in the hashtable, then return the subset?
:cheesy:

That's pretty much what a built-in function would have to do anyway so the performance will be identical (or likely even better, as custom code can anticipate things that generic code cannot) when writing custom code.

If you're concerned about performance you might want to consider caching the most frequently requested subsets, but unless your Map is very large indeed (think thousands of entries) the filtering should not take more than a fraction of a second.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.