wood burning stoves 2.0*
The moose likes Java in General and the fly likes WildCard search on keys in TreeMap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "WildCard search on keys in TreeMap" Watch "WildCard search on keys in TreeMap" New topic
Author

WildCard search on keys in TreeMap

Sailaja Yendluri
Greenhorn

Joined: Jun 24, 2003
Posts: 2
Hi all,
I have a TreeMap with String as its key and an array of objects as its value.the size of array varies with each key.
The output of the tMap.toString() willbe of the form,
{1-1=[], 1-2=[], 1-3=[], 1-4=[], 1-5=[], 1-6=[], 1-7=[], 1-8=[], 1-9=[], 1-10=[], 2-1=[], 2-2=[], 2-3=[], 2-4=[], 2-5=[], 2-6=[], 2-7=[]}
now comes the actual problem
i need to collect only those values(ie the arrays)from the treemap, whose key matches/contains "1-" structure.
PS:The data in treemap is huge.i have around 250 entries in the treemap.
i am kind of stuck here. pls help me out on this.
Any suggestions/help provided will be very much helpful.Thanks in advance
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
IF the "1-" is at the very beginning of the key, then you can exploit the sorting of the TreeMap like this:

Unforturnately this only works it the "1-" is at the beginning. Otherwise you've just got to iterate through the whole entry set to see which keys match what you want:

PS:The data in treemap is huge.i have around 250 entries in the treemap.
Eh, I suppose it depends on what you're doing, but that doesn't sound all that huge to me. There's a good chance that even if you iterate through all entries of the Map to check for "1-", it won't really take that long. Try it and see if the performance is acceptable; if it is, don't worry any more about it.


"I'm not back." - Bill Harding, Twister
Sailaja Yendluri
Greenhorn

Joined: Jun 24, 2003
Posts: 2
Thank You very much Jim !! Using SortedMap, was a "Gun shot" solution for my problem !!I have tested it, implemented it and the program is up in running in the production build.It is working as required.
Thanks once again Jim for u'r timely help !!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: WildCard search on keys in TreeMap