• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hashtable - SQL Like operation

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I need to have sql's LIKE operation in hashtable(or anyother collection object) key lookup. Any idea how to do it.
Eg :
Hashtable hash = new Hashtable();
hash.put("KEY_1234","ONE");
hash.put("KEY_5236","ONE");
hash.put("KEY_6278","ONE");

hash.get("KEY_%23%"); --> should return KEY_1234 and KEY_5236.

Any idea how to do it without looping through the hash

Thanks
Anand
 
Ranch Hand
Posts: 171
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't do it using the standard Hashtable. You will have to use some kind of regular expression matching, which means looping through the collection unless you implement something really sophisticated.

You may want to check out Lucene which is a text search engine, that can do what you want.

Geoffrey
 
Krish
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Geoffrey.
I can't do the looping of keys because the number of keys in the hash is high(atleast 5000 keys).
I checked with Lucene too but they seem to be providing text level search and not w.r.to objects (unless I've overlooked).
Any other suggestions :roll:

Thanks
Anand
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How often do you iterate over those 5000 entries?
5000 doesn't look as a high value to me.
Did you test an iterating algorithm?
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Krish",
Note that we require proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks,
Jeanne
Forum Bartender
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Krish,
I agree with Stefan - 5000 isn't that many. Try it out and see how the performance is. If it turns out to be a bottleneck, you can split it into sublists by first character or something similar.

One suggestion: wrap the HashMap in your own data structure. This will make changing the implementation much easier if you need it at a later date.
 
Danger, 10,000 volts, very electic .... tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic