Skip to main content
deleted 161 characters in body
Source Link
Dcoto
  • 143
  • 9

I think this is because the else statement is now taking care of the out of bounds, and the previous conditions everything in between. Can anyone shed any light.

I think this is because the else statement is now taking care of the out of bounds, and the previous conditions everything in between. Can anyone shed any light.

added 493 characters in body
Source Link
Dcoto
  • 143
  • 9

Changed if statment to this and seems to work fine.

 if (i + 1 == arr2.size()) { result = result + arr2.get(i); } else if (arr2.get(i) % 2 == 0 && i < arr2.size() && arr2.get(i + 1) % 2 ==0) { result = result + arr2.get(i) + "-"; } else{ result = result + arr2.get(i); } 

I think this is because the else statement is now taking care of the out of bounds, and the previous conditions everything in between. Can anyone shed any light.

Changed if statment to this and seems to work fine.

 if (i + 1 == arr2.size()) { result = result + arr2.get(i); } else if (arr2.get(i) % 2 == 0 && i < arr2.size() && arr2.get(i + 1) % 2 ==0) { result = result + arr2.get(i) + "-"; } else{ result = result + arr2.get(i); } 

I think this is because the else statement is now taking care of the out of bounds, and the previous conditions everything in between. Can anyone shed any light.

edited title
Link
weston
  • 55k
  • 23
  • 151
  • 209

Java out Out of bounds error using ArrayList

added 145 characters in body
Source Link
willeM_ Van Onsem
  • 481.8k
  • 33
  • 483
  • 624
Loading
Source Link
Dcoto
  • 143
  • 9
Loading