• 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

Excel Match equivalent in java.

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I hope you could help me.

I have an array of 10000 generated values and I would like to search the array like the Excel match function. I have looked at the following post and tried to implement it without success, I get strange values back:

https://coderanch.com/t/531662/java/java/Array-function-similar-Excel-Match

I would like to do the same but with decimal values. I.e. if a value is not found in the array, return the closest value.

My Code:


I also tried the following:



Many thanks for your help in advance.


Regards


Richard
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's wrong with the NavigableSet / TreeSet solution?
 
Richard Cook
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont seem to be getting the right numbers, does the code look right, if it does I will double check everything else.

Regards


Richard
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The one thing that stands out is that you said in the first post you want the closest value, whereas floor() returns the closest below. Could that be the problem with the results you're expecting? If it is, you might need to use ceiling() as well, and see which is closer.
 
Ranch Hand
Posts: 66
Android IntelliJ IDE Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Doesn't floor() return a match less than or equal to?
 
Keith Rainey
Ranch Hand
Posts: 66
Android IntelliJ IDE Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
NavigableSet docs

.lower and .higher would behave as you described .ceiling and .floor would return exact match, also.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic