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();
}
}


posts - 403, comments - 310, trackbacks - 0, articles - 7
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

1.23 Java notes

Posted on 2007-04-22 20:22 ZelluX 阅读(97) 评论(0)  编辑  收藏 所属分类: OOP
2007-01-23 22:47:56
只有注册用户登录后才能发表评论。


网站导航: