The moose likes Beginning Java and the fly likes Array function similar to Excel Match? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Array function similar to Excel Match?" Watch "Array function similar to Excel Match?" New topic
Author

Array function similar to Excel Match?

Raymond Holguin
Ranch Hand

Joined: Aug 11, 2009
Posts: 47
http://www.techonthenet.com/excel/formulas/match.php

basically have an array and search it. And like the excel Match function, if the value is not found in the array it will return the index of the next closest value? This is something thats easy to code, but i was just tryin to see if there was a built in java method that would do something like this for me.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

Not that I'm aware of. Well, not for arrays. SortedSet NavigableSet (with implementing class TreeSet) does have something like this, with the head and tail sets.

NavigableSet is a bit better than SortedSet because it allows the bound for the head / tail sets to be inclusive or not; with SortedSet you cannot specify this yourself.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Raymond Holguin
Ranch Hand

Joined: Aug 11, 2009
Posts: 47
awesome man thanks that almost worked lol. i using strings of time and the set doesn't know the difference between AM and PM when comparing strings



always returns 11:30 PM. so ill have to do some data manipulation i guess and convert to military time or something before i insert the data into the set. but either way its a step in the right direction and better than writing my own function!
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4163
    
    3

Arrrays#binarySearch can return a meaningful negative value when an exact match is not found.


luck, db
There are no new questions, but there may be new answers.
Ernie Mcracken
Ranch Hand

Joined: Feb 13, 2011
Posts: 33

The strings in your set will be sorted alphabetically so if you want to take into account the AM / PM you would need to use something other than String or have a class that implements comparable and overides compareTo() to take it into account i think.


You're on a gravy train with biscuit wheels Roy.
Raymond Holguin
Ranch Hand

Joined: Aug 11, 2009
Posts: 47
Cool i got it, thanks again for showing me that NavigableSet!!

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Array function similar to Excel Match?
 
Similar Threads
find method in the interface
Read text values in javascript
Excel Match equivalent in java.
is it neccessary to overide the equals and hashcode method of value objects for doing get operation?
ascii to number conversion in java