How to return multiple objects from a Java method?

前端 未结 25 3652
眼角桃花
眼角桃花 2020-11-21 23:55

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<

25条回答
  •  佛祖请我去吃肉
    2020-11-22 00:31

    Use of following Entry object Example :

    public Entry methodname(arg)
    {
    .......
    
    return new AbstractMap.simpleEntry(instanceOfA,instanceOfB);
    }
    

提交回复
热议问题