permaculture playing cards*
The moose likes Java in General and the fly likes Excel Match equivalent in java. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Excel Match equivalent in java." Watch "Excel Match equivalent in java." New topic
Author

Excel Match equivalent in java.

Richard Cook
Greenhorn

Joined: Aug 18, 2010
Posts: 22
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

Joined: Oct 27, 2005
Posts: 19762
    
  20

What's wrong with the NavigableSet / TreeSet solution?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Richard Cook
Greenhorn

Joined: Aug 18, 2010
Posts: 22
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

Joined: Apr 06, 2010
Posts: 4467
    
    8

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

Joined: Jan 19, 2011
Posts: 66

Doesn't floor() return a match less than or equal to?


Keith Rainey
OCPJP6
Keith Rainey
Ranch Hand

Joined: Jan 19, 2011
Posts: 66

NavigableSet docs

.lower and .higher would behave as you described .ceiling and .floor would return exact match, also.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Excel Match equivalent in java.