I need your help with a small problem.
It there a possibility (in Java or an abstract solution) to transform a arbitrary String into an Integer with the property, that the alphabetically ordering does also work with the Integer?
Example:
House < Tree < Zoo in alphabetically order.
I would like to transform those Strings into Integer, so that the ordering is also available. Important is, that the concrete Strings are not known before. That means it should be a unique transformation.
I hope someone can help me.
Regards,
Michael
No, it’s not possible. Let’s say you have two strings which represent 1 and 2. You can always make another string which would fit between them alphabetically e.g.
If you know the strings you’re dealing with have a maximum length, then this is possible. For example, suppose your string has length <= 3. Take a string abc, and convert each letter to a number, where A = 1, B = 2, …, Z = 26. If the string is less than 3 characters long, fill in the blanks at the end with zeroes. Then the value is:
Then: