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);

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.


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

2 requirements: 1) Replace multiple FOR loop with FORALL 2) use IF-THEN-ELSE condition while inserting data into table

sql for-loop plsql condition forall

My requirement is a bit different. I have two nested FOR loops that fetch data and based on certain condition it inserts sorted data into table.

Can you suggest me some open source projects in Javascript or PHP that I can study easily?

php javascript open-source

I have come to learn that my learning habits in programming is by looking at other people codes and hack it myself. My favourite languages are PHP and Javascript, so I want you to please share to m...

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.