Your getNextIndex
method can be simplified using the ternary operator
private int getNextIndex(int index){
return index == queue.length - 1 ? 0 : index + 1;
}
Besides this simplification, I agree with Kinjal's answer.
As your index
variable is local to only that method, there's no reason to use index++
which will modify the index variable, that's why I'm using index + 1
here instead.