So we had a case where we would have an object, where key is id (int) and the value is the string. But we noticed that most of the times, we look up id based on the string,
No, there is no limit for the string length (as long as it fits into memory), and your implementation seems okay too. It's acutally quite common to have those 'turned around' arrays with e.g. boolean values. And as to the strings as keys: The strings are immutable symbols that are stored at a certain address, and what's actually used as the index for the array is that address (aka pointer aka reference) and not the string itself.