To avoid the duplicate claims, I've looked at this post and it isn't exactly what I wanted.
Every other 2D ArrayList question involved double
or int
numbers; my question is about Strings
.
What I'm doing
I have a 2D ArrayList, defined like this:
ArrayList<ArrayList<String>> namesAndNumbers = new ArrayList<ArrayList<String>>();
The idea is that the first item in every row of ArrayLists contains the names, and the rest of the columns in each row contains the phone numbers (unknown amount). Therefore I would like to avoid converting it to a regular array.
Sample
Let's say I've populated my ArrayList and I have this:
{"Mike", "(805) 766-4920"}
{"Emily", "(705) 668-9292", "(705) 555-1060"}
{"James", "(605) 965-2000"}
I expect my output to be this:
{"Emily", "(705) 668-9292", "(705) 555-1060"}
{"James", "(605) 965-2000"}
{"Mike", "(805) 766-4920"}
I want to keep the numbers corresponding with the names, but simply sort the array by the name.
What answers I hope for
I'm hoping for a built-in function manipulation type of thing, but I'd be fine if someone created a sorting array method for me with an 2D ArrayList as the input. I haven't seen any question that answers this issue explicitly. I will continue trying to come up with an answer myself as well.