I want to return two objects from a Java method and was wondering what could be a good way of doing so?
The possible ways I can think of are: return a HashMap<
Why not create a WhateverFunctionResult
object that contains your results, and the logic required to parse these results, iterate over then etc. It seems to me that either:
I see this sort of issue crop up again and again. Don't be afraid to create your own container/result classes that contain the data and the associated functionality to handle this. If you simply pass the stuff around in a HashMap
or similar, then your clients have to pull this map apart and grok the contents each time they want to use the results.