I have a hierarchical list like below and I want to convert it to a flat list.
I have wrote a method called convertToFlatList
If a Member has children, you correctly add the children to the flattened list, but miss the Member itself. Just move the addition of the member outside of the else block add you should be fine:
private static List
convertToFlatList(List memberList, List flatList)
{
for (Member member : memberList)
{
// Always add the member to flatList
flatList.add(memeber);
// If it has children, add them toore
if (member.getChildren() != null)
{
convertToFlatList(member.getChildren(), flatList);
}
}
return flatList;
}