我試圖拆分一個數組,將一部分存儲在一個數組中,另一部分存儲在另一個數組中。然後即時嘗試翻轉2並將它們存儲在一個新的數組中。這裏是我有java.lang.ArrayIndexOutOfBoundsException錯誤?
public int[] flipArray(){
int value = 3;
int[] temp1 = new int[value];
int[] temp2 = new int[(a1.length-1) - (value+1)];
int[] flipped = new int[temp1.length+temp2.length];
System.arraycopy(a1, 0, temp1, 0, value);
System.arraycopy(a1, value+1, temp2, 0, a1.length-1);
System.arraycopy(temp2, 0, flipped, 0, temp2.length);
System.arraycopy(temp1, 0, flipped, temp2.length, temp1.length);
return flipped;
}
private int[]a1={1,2,3,4,5,6,7,8,9,10};
嗨,請你可以發佈異常消息,因爲它會告訴我們哪一行代碼給出的數組索引超出了界限錯誤。 – ThePerson
可能的重複[什麼導致java.lang.ArrayIndexOutOfBoundsException,我該如何防止它?](http://stackoverflow.com/questions/5554734/what-causes-a-java-lang-arrayindexoutofboundsexception-and-how- DO-I-防止-IT) – Raedwald