-3

There are many sorting algorithms e.g. bubble sort, insertion sort, merge sort etc. When sorting rows of JTable what algorithm is used? anybody please.

Nadeem
  • 195
  • 1
  • 1
  • 14
  • @Sarz There is a class TableRowSorter which can be added to a JTable and you don't have to do anything else just click on table header and it will sort the table data. Tell me in this default scenario what alogo is used??? – Nadeem Nov 18 '14 at 10:19
  • `TableRowSorter` uses comparator for sorting, try to search, or read [here](http://www.coderanch.com/t/263747/java-programmer-SCJP/certification/sorting-algorithm-comparator-comparable), [here](https://docs.oracle.com/javase/tutorial/collections/algorithms/#sorting) – alex2410 Nov 18 '14 at 10:23
  • @Sarz- Please explain "It wil get sorted if you arrange sorted data somehow" – Nadeem Nov 18 '14 at 10:29
  • Sorry the links in the answer below are not useful – Nadeem Nov 18 '14 at 10:41

1 Answers1

2

Dual-Pivot Quicksort has been used by Arrays.sort(...) since Java 1.7.0:

//@see javax.swing.DefaultRowSorter#sort()
private Row[] viewToModel;
public void sort() {
  //...
  // sort them
  Arrays.sort(viewToModel);

Edit

Sorry I missed, Arrays.sort(int[]) not using:

public static void sort(int[] a) {
    DualPivotQuicksort.sort(a, 0, a.length - 1, null, 0, 0);
}

correct:

public static void sort(Object[] a) {
    if (LegacyMergeSort.userRequested)
        legacyMergeSort(a);
    else
        ComparableTimSort.sort(a, 0, a.length, null, 0, 0);
}
aterai
  • 9,658
  • 4
  • 35
  • 44