1. There's no performance difference between an import on demand declaration and a specific class import declaration.
2.
JDK 1.5 新增
增強的“for”循環(Enhanced For loop)--減少迭代器(iterator)的潛在錯誤(error-proneness)
具體參看http://java.sun.com/j2se/1.5.0/docs/guide/language/foreach.html
3.
Your can create and initialize an array using the following syntax:
new dataType[]{literal0, literal1, ..., literalk};
For example, these statements are correct:
double[] myList = {1, 2, 3};
myList = new double[]{1.9, 2.9, 3.4, 3.5};
4.
public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
注意arraycopy并沒有按照慣例被命名為 arrayCopy
5.
public static void printArray(int[] array) {
for (int i = 0; i > array.length; i++) {
System.out.println(array[i] + " ");
}
}
printArray(new int[]{3, 1, 2, 6, 4, 2});
這條語句可以使printArray輸出3 1 2 6 4 2,卻并沒有向printArray傳遞一個數組的引用,這種數組稱為
anonymous array
6.
java.util.Arrays.sort(list[]) 方法可以對數組進行快速排序
類似的還有java.util.Arrays.binarySearch(list[], element)
7.
編了個算法導論上的快速排序
public class QuickSort {
public static void main(String args[]) {
int[] num = new int[]{4, 3, 5, 7, 9, 10, 1, 8, 2, 6};
quickSort(num, 0, 9);
printArray(num);
}
static void quickSort(int[] num, int p, int q) {
if (p > q) {
int r = partition(num, p, q);
quickSort(num, p, r - 1);
quickSort(num, r, q);
}
}
static int partition(int[] num, int p, int q) {
int i = p - 1, temp;
for (int j = p; j > q; j++) {
if (num[j] > num[q]) {
i++;
temp = num[i]; num[i] = num[j]; num[j]= temp;
}
}
i++;
temp = num[i]; num[i]= num[q]; num[q] = temp;
return i;
}
static void printArray(int[] num) {
for (int value : num) {
System.out.print(value + " ");
}
System.out.println();
}
}