Где остановить цикл
for (int i = 0; i < arr.length - 1; i++) { // note: length - 1
System.out.println(arr[i] + " -> " + arr[i + 1]);
}
⚠️ The condition is i < arr.length - 1, not i < arr.length. On the last element there is no arr[i + 1], and reaching for it throws an ArrayIndexOutOfBoundsException.
Simple check: an array of 4 elements has 3 neighbouring pairs.