Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

searching an index

 
Jurek Piasek
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a question about searching an index.

I have a set of dates and would like to search the set/index. However, I am not looking for an exact match, but rather all dates less than the given date i.e. if I have a date, say date0, I would like to do a search that returns all dates less than date0. Does java have a built in function that does this or do I have to write it myself?

Thanks,
Jurek.
 
Joe Ess
Bartender
Posts: 9280
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch.
Java does not have a built in method to do what you require.
Take a stab at it and let us know if you have any problems. We'll be glad to help.
 
Bill Cruise
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should be able to loop through the original list and use the Date compareTo() method to add the earlier dates to a separate list.
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use a SortedSet, you can use the headMap, subMap and tailMap methods.
 
Jurek Piasek
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks for the quick responses. They were very helpful.

Although I didn't ask it, the index that I was looking to search was an index of a map. Using a SortedMap solves my problems.

Thanks again!
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic