Is there a way in Java to access two or more non-consecutive indexes of an array at the same time?
For example, I have the following array:
int myArray = {1, 3, 5, 7, 9}
I know I can access one single index or consecutive indexes (using Arrays.copyOfRange) of this array. But if want to print out indexes 1 and 3 of this array; do I have to use the following:
System.out.print(myArray[1] + myArray[3])
I am expecting some syntax like the following; clearly, they are wrong
System.out.print(myArray[1,3])
or
int indexes = {1,3}
System.out.print(myArray[indexes])