returning multiple values in Java

后端 未结 6 542
时光说笑
时光说笑 2020-12-11 19:14

Preamble: I am aware of using a list or other collections to return a result but then I have to go through the list plucking the results out: see 2nd example

Preambl

6条回答
  •  离开以前
    2020-12-11 20:03

    Returning an extended Holder seems better than returning a List:

    class Holder {
        int value1;
        String value2;
        Holder(int value1, String value2) {}
    }
    
    Holder foobar() {
        return new Holder(1, "bar");
    }
    

提交回复
热议问题