Skip to main content
added 178 characters in body
Source Link
Simon Forsberg
  • 59.4k
  • 9
  • 156
  • 309

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.

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.

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.

Source Link
Simon Forsberg
  • 59.4k
  • 9
  • 156
  • 309

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.