Java 7 sorting “optimisation”

前端 未结 3 1810
长发绾君心
长发绾君心 2021-02-03 23:54

In Java6 both quicksort and mergesort were used in Arrays#sort, for primitive and object arrays respectively. In Java7 these have both changed, to DualPivotQuickso

3条回答
  •  佛祖请我去吃肉
    2021-02-04 00:08

    This is only an answer to the general question.

    You can look at the bytecode and try to understand the differences. I.e. you could write yourself a simple example using both a[i] = b; i++; and a[i++] = b; and see whats the difference.

    The simplest way to show the bytecode is the javap program (should be included in you JDK). Compile the code with javac SomeFile.java and run javap on the code: javap -c SomeFile (the -c switch tells javap to output the bytecode for each method in the file).

    If you are using eclipse you could also try this one.

提交回复
热议问题