-5
我注意到在子陣列上使用Java Arrays.sort()時會出現奇怪的行爲。這是一個演示程序。這是Java中的錯誤嗎?有關子陣列上的Java Arrays.sort()的問題 - 這是一個錯誤嗎?
package sorted_subsegments;
import java.util.Arrays;
public class sortTest {
public static void main(String[] args) {
int A[] = {3, 2, 1};
System.out.format("A: %s\n", Arrays.toString(A));
Arrays.sort(A, 0, 1);
System.out.format(" after sub array sort on A: %s\n", Arrays.toString(A));
System.out.println("Should be A: [2, 3, 1]");
Arrays.sort(A);
System.out.format(" whole array sort on A: %s\n", Arrays.toString(A));
}
}
而結果是? – VLef
你有什麼問題? – Blank
您是否閱讀過[javadoc](https://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html#sort-int:A-int-int-)? 「toIndex - 要排序的最後一個元素的索引,*** exclusive ***」 – assylias