I'm trying to practice quick sort list using java, I think this is correct but it shows "Exception in thread main..."
public class QuickSort {
  public static void sort(List<Integer> list) {
    sort(list, 0, list.size() - 1);
  }
  public static void sort(List<Integer> list, int from, int to) {
    if (list.size() <= 1) {
        return;
    }
    int pivot = from;
    int left = from + 1;
    int right = to;
    while (left < right) {
        while (list.get(pivot) >= list.get(left)) {
            left++;
        }
        while (list.get(pivot) <= list.get(right)) {
            right--;
        }
        if (left < right) {
            Collections.swap(list, left, right);
        }
    }
    Collections.swap(list, pivot, left - 1);
    sort(list, from, pivot - 1);
    sort(list, pivot + 1, to);
  }
}
				
                        
Try with this: