Any suggestions for improvement are welcome.public static int[] concatArrays(int[] a1, int[] a2) {    int n1 = a1.length;    int n2 = a2.length;    if(n1 == 0) return a2;    if(n2 == 0) return a1;    int n = n1 + n2;    int counter = 0;    int[] result = new int[n];    for(; counter < n1; counter++) {        result[counter] = a1[counter];    }    for(; counter < n; counter++) {        result[counter] = a2[counter - n1];    }    return result;}public static int[] concatArrays(int[] a1, int a2) {    int[] a2New = new int[] {a2};    return concatArrays(a1, a2New);}public static int[] sort(int[] data) {    if(data.length == 0) return new int[0];    int nBefore = 0;    int nAfter = 0;    int[] beforeArray = new int[data.length];    int[] afterArray  = new int[data.length];    for(int i = 1; i < data.length; i++) {        if(data[i] < data[0]) {            beforeArray[nBefore++] = data[i];        }        else {            afterArray[nAfter++] = data[i];        }    }    int[] beforeArrayTrimmed = new int[nBefore];    int[] afterArrayTrimmed = new int[nAfter];    System.arraycopy(beforeArray, 0, beforeArrayTrimmed, 0, nBefore);    System.arraycopy(afterArray, 0, afterArrayTrimmed, 0, nAfter);    return concatArrays(            concatArrays(sort(beforeArrayTrimmed), data[0]),            sort(afterArrayTrimmed)    );}
Plain old quick sort
java;quick sort
Your Quick sort will not be as quick as most quicksorts are designed to be.Your code is continually creating, populating, and discarding arrays of integers. Quick-sort algorithms will almost always have a single array and do the sorting 'in place'. This saves a huge amount of copy overhead.In fact, your copy overhead is making the system run many, many times slower as you copy data from one array to another.Since this answer is essentially saying you're doing it wrong, it's not really a code review, but, you should read up on how others have done a quick sort. References I recommend are:Wikipedia Quick SortRosetta CodeOther Code Review answersAdditionally, you should read up on the standard array handling available in the Java libraries. Your code here (completely unnecessary if you do an in-place quick sort):public static int[] concatArrays(int[] a1, int[] a2) {    int n1 = a1.length;    int n2 = a2.length;    if(n1 == 0) return a2;    if(n2 == 0) return a1;    int n = n1 + n2;    int counter = 0;    int[] result = new int[n];    for(; counter < n1; counter++) {        result[counter] = a1[counter];    }    for(; counter < n; counter++) {        result[counter] = a2[counter - n1];    }    return result;}Can easily be reduced to:public static int[] concatArrays(int[] a1, int[] a2) {    int[] result = Arrays.copyOf(a1, a1.length + a2.length);    System.arrayCopy(a2, 0, result, a1.length, a2.length);    return result;}