• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

WildCard search on keys in TreeMap

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sailaja Yendluri
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 !!
 
reply
    Bookmark Topic Watch Topic
  • New Topic