public static void main(String args[]) {
myMethod(); // i am calling static method from main()
}
.
public static ? myMethod(){
No. Java methods can only return one result (void, a primitive, or an object), and creating a struct-type class like this is exactly how you do it.
As a note, it is frequently possible to make classes like your ReturningValues immutable like this:
public class ReturningValues {
public final String value;
public final int index;
public ReturningValues(String value, int index) {
this.value = value;
this.index = index;
}
}
This has the advantage that a ReturningValues can be passed around, such as between threads, with no concerns about accidentally getting things out of sync.