return two variables from one method

前端 未结 5 1764
小蘑菇
小蘑菇 2021-02-08 04:30

How to write the following code correctly?

public String toString(int[] position, int xOffset, int yOffset) {
    String postn = String.format(\"[%d,%d]\", posit         


        
5条回答
  •  名媛妹妹
    2021-02-08 05:01

    When using Java 8 you could make use of the Pair class.

    private static Pair foo (/* some params */) {
        final String val1 = "";  // some calculation
        final String val2 = "";  // some other calculation
    
        return new Pair<>(val1, val2);
    }
    

    Otherwise simply return an array.

提交回复
热议问题