1 Answer
1

Generics aren't the answer here, because all your data objects are ZooEntity objects. If you had related classes such as Animal, Vegetable and Mineral it would make sense to have a generic method dealing with "something that has an ID", but that's not the case here.

What you do have is things, collections of things and nested collections of things. There is no natural interface that you could use or define to do the job at hand with one function - collections simply don't have a getId() method. You could simplify your code using recursion, but that would mean instanceof checks at every level of processing. As long as you only have linear lists and singly-nested lists, the most obvious route is simply to have your second method call the first one.