Indexes use "zero-based numbering" >> https://en.wikipedia.org/wiki/Zero-based_numbering
String example = "01234";
System.out.println(example.size()); //Prints out 5
System.out.println(exmaple.indexOf("1")); //Prints out 1
Your for statement needs to be checking up TO the last index
for(int i=right_index;right_index<last;i++)
OR (not recommended)
for(int i=right_index;right_index<=last-1;i++) //Works, but not recommended due to conventions
//index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Random array: 17 14 3 4 1 10 13 9 3 1 6 9 10 2 17 8 10 5 7 8
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 20