I have an ArrayList with several objects per index. I want to sort this list alphanumerically by one object in particular. The object is "my_id" and the values for this object can look similar to: 1A, 10B, 11B, 2C, 205Z, etc.
I need to sort these to come out: 1A, 2C, 10B, 11B, 205Z. Where the numeric part is sorted first, then the alpha- part is sorted secondary. 1,2,3,4,5,... A,B,C,D,E,...
I checked out some alphanumeric string sorting that worked really well: http://sanjaal.com/java/206/java-data-structure/alphanumeric-string-sorting-in-java-implementation/
Unfortunately I can only get that object to sort and I lose the other objects in my ArrayList as a consequence. I really need a sorting algorithm that can rearrange the ArrayList index's by the object of my choosing and not lose the other objects!
Is there a method to do this already out there? I've been unable to find one. I think it's useful to add that all the objects in my ArrayList are mapped strings: ArrayList<HashMap<String, String>>
[edit]
I have my array:
ArrayList<HashMap<String, String>> al
I then store the object:
String[] alphaNumericStringArray = new String[al.size()];
for(int i = 0; i < al.size(); i++)
{
alphaNumericStringArray[i] = al.get(i).get("my_id");
}
I now sort the string array:
// Sort the array now.
Arrays.sort(alphaNumericStringArray, new AlphanumericSorting());
I then put the object back:
for(int i = 0; i < al.size(); i++)
{
HashMap<String, String> map = new HashMap<String, String>();
map.put("my_id", alphaNumericStringArray[i]);
// TODO, need to append the rest of the objects.
al.set(i, map);
}
I know what you're thinking, I'm not adding all the objects BACK when I re-map it. This is what I have currently, but what I want is a way to sort the whole list not just the one object "my_id". I want to rearrange the indexes so I don't have to re-map everything at the end.