File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Hashtable - SQL Like operation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Hashtable - SQL Like operation" Watch "Hashtable - SQL Like operation" New topic
Author

Hashtable - SQL Like operation

Krish
Greenhorn

Joined: Jul 18, 2002
Posts: 8
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


Anand
Geoffrey Falk
Ranch Hand

Joined: Aug 17, 2001
Posts: 171
    
    1
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


Sun Certified Programmer for the Java 2 Platform
Krish
Greenhorn

Joined: Jul 18, 2002
Posts: 8
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
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

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?


http://home.arcor.de/hirnstrom/bewerbung
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31074
    
232

"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


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31074
    
232

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hashtable - SQL Like operation