You have 3 options:
1.)
return an object array:
- return new Object[] {new Integer(isFirstValue), new Integer(isSecondValue)};
2.)
return an instance of an inner class:
- private static class Results{} {
-
public final int isFirstValue;
-
public final int isSecondValue;
-
private Results(int isFirstValue, int isSecondValue) {
-
this.isFirstValue = isFirstValue;
-
this.isSecondValue = isSecondValue;
-
}
-
}
Then return by:
- return new Results(isFirstValue , isSecondValue);
If "results" would be the returned object, you can access the two results with "results.isFirstValue" and "results.isSecondvalue". I agree that it's a lot of boilerplate code to write, but the advantage is: more clear than accessing by index, for example "object[1]"; it can be inlined by compiler; no in/outboxing.
3.)
For fastest speed, put both integers (32 bits) together in a long (64 bits) and return that long. The lower 32 bits of the long represents the first integer and the higher 32 bits of the long represents the second integer. Use shifting and bit functions to extract the original integers from the long. (For example "originalInteger = longresult & 0xFFFF" returns the first integer.
I assume from the name "isFirstValue" that you really want to store a boolean and not an integer. If that is the case, then you can put both values in an integer, using the first bit for the first boolean and the second bit for the second boolean. then you can retrieve them later by a simple bit-test.
Example:
-
int isFirstValueBit = (isFirstValue ? 0 : 1);
-
int isSecondValueBit = (isSecondValue ? 0 : 2);
-
int resultInt = isFirstValue + isSecondvalue;
-
return resultInt;
-
...
-
if (resultInt & 1 != 0) then System.out.println("isFirstValue was set");
-
if (resultInt & 2 != 0) then System.out.println("isSecondValue was set");