Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Excel Match equivalent in java.

 
Richard Cook
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • 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:

http://www.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
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's wrong with the NavigableSet / TreeSet solution?
 
Richard Cook
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • 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
 
Matthew Brown
Bartender
Posts: 4565
8
  • Mark post as helpful
  • send pies
  • 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.
 
Keith Rainey
Ranch Hand
Posts: 66
Android Eclipse IDE IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doesn't floor() return a match less than or equal to?
 
Keith Rainey
Ranch Hand
Posts: 66
Android Eclipse IDE IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NavigableSet docs

.lower and .higher would behave as you described .ceiling and .floor would return exact match, also.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic