How to return more than one value from a function in Java? Can anyone give sample code for doing this using tuples? I am not able to understand the concept of tuples.
<
Is this what you are looking for?
public class Tuple {
public static void main(String[] args) {
System.out.println(f().a);
System.out.println(f().b);
}
static Pair f() {
Tuple t = new Tuple();
return t.new Pair("hi", 3);
}
public class Pair {
public final String a;
public final Integer b;
public Pair(String a, Integer b) {
this.a = a;
this.b = b;
}
}
}