This is how I would have done it, not sure if I am being helpful here. I'm fairly new to Java and programming in general.
//Method that takes an ArrayList, filter the list, and returns a new ArrayList
public static ArrayList<BabyName> filterArrayList(ArrayList<BabyName> inputList, int filter) {
ArrayList<BabyName> returnList = new ArrayList<>();
for (BabyName babyName: inputList) {
if (babyName.getRank() == filter)
returnList.add(babyName);
} return returnList;
}
This block of code basically iterates the TreeMap, and calls the above method. The ArrayList returned by the above method gets added to a new ArrayList mFilteredList.
ArrayList<BabyName> mFilteredList = new ArrayList<>();
for (Iterator<ArrayList<BabyName>> iterator = myMap.values().iterator(); iterator.hasNext(); ) {
ArrayList<BabyName> nameList = iterator.next();
mFilteredList.addAll(filterArrayList(nameList, 2));
}