Getting back specific lower bounds value from inputted key in LinkedHashMap

I have an LinkedHashMap that uses the values from a char array as its key adds integers 1 to the size of the char array as its values:

hmConvert = new LinkedHashMap<Character, Integer>();
for (int m = 0; m < referenceString.length; m++) {
    hmConvert.put(referenceString[m], m);
}

an example of values in the char array would be:

'0', '1', '5', '3', '6', '6', '4', '4', '5', '5', '6', '0', '3', '3', '5'

When i use the get method on the LinkedHashMap it is returns the higest key back, for example:

int test = hmConvert.get(5);
System.out.println(test);

The output would be: 14

I need the output in this case to be the LOWEST value after a GIVEN input value. So if I inputted 4 as the input, the returned value would be 8.

How would I go about doing this.

Answers


Okay first of all, I assume you mean int test = hmConvert.get('5');, because in your example, it would be null, not 14.

You can accomplish this goal simply by putting the values in backwards (so the first keys are the ones that don't get overwritten). In other words, do this:

for (int m = referenceString.length - 1; m >= 0; m--) {
  hmConvert.put(referenceString[m], m);
}

Need Your Help

File/Calls substitution like LD_PRELOAD

linux bash system-calls utility

Does there is usual utility which makes a substitution on some calls like execve and open? Like LD_PRELOAD for calls.

Library to create code outline

python ruby outline

Is there a python or ruby library to create a code outline for the given code? The library should support multiple languages.

Managed/shared web hosting with PHP 5.3 +

php joomla hosting web-hosting

Does anyone know of any hosting providers running PHP 5.3 + ?? We need this for our custom Joomla sites.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.