Bubble sort class in Java I have written this class which sorts the array using bubble sort. Please let me know how can I improve it. (I don't like recurrent code in if/else statement)

public class BubbleSort {

public static void numbers(int[] array){
    numbers(array, '&lt;');
}

public static void numbers(int[] array, char direction){
    if(direction == '&lt;'){
        for(int i = 0; i &lt; array.length - 1; i++){
            for(int j = 0; j &lt; array.length - i - 1; j++){

                if(array[j] &lt; array[j + 1]){
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                }
            }
        }
    }
    else{
        for(int i = 0; i &lt; array.length - 1; i++){
            for(int j = 0; j &lt; array.length - i - 1; j++){

                if(array[j] &gt; array[j + 1]){
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                }
            }
        }
    }
}

public static void letters(char[] array){
    letters(array, '&lt;');
}

public static void letters(char[] array, char direction){
    if(direction == '&lt;'){
        for(int i = 0; i &lt; array.length - 1; i++){
            for(int j = 0; j &lt; array.length - i - 1; j++){

                if(array[j] &lt; array[j + 1]){
                    char tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                }
            }
        }
    }
    else{
        for(int i = 0; i &lt; array.length - 1; i++){
            for(int j = 0; j &lt; array.length - i - 1; j++){

                if(array[j] &gt; array[j + 1]){
                    char tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                }
            }
        }
    }
}   
}
Bubble Sort has an inefficient worst case.  In general, you could speed things up by switching from this \$O(n^2)\$ sort to one of the \$O(n \log n)\$ sorts, e.g. Quicksort.  Simplest would be to just use Arrays.sort but perhaps this is a programming exercise (tagging as reinventing-the-wheel would let reviewers know that).  


        for(int i = 0; i &lt; array.length - 1; i++){
            for(int j = 0; j &lt; array.length - i - 1; j++){

                if(array[j] &lt; array[j + 1]){
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                }
            }
        }



The one thing that Bubble Sort can do well is handle sorted input efficiently in \$O(n)\$ time.  But you don't do that.  

        for (int i = 0; i &lt; array.length - 1; i++) {
            boolean bubbled = false;
            for (int j = 0; j &lt; array.length - i - 1; j++) {
                if (array[j] &lt; array[j + 1]){
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    bubbled = true;
                }
            }

            if (!bubbled) {
                return;
            }
        }


Now it will return after a single pass if the input is sorted.  If the input is almost sorted, it may return on the second or third pass.  

You can save a calculation an outer loop iteration if you're really trying to optimize.  

        for (int i = array.length - 1; i &gt; 0; i--) {
            boolean bubbled = false;
            for (int j = 0; j &lt; i; j++) {
                if (array[j] &lt; array[j + 1]){
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    bubbled = true;
                }
            }

            if (!bubbled) {
                return;
            }
        }


Now you don't have to calculate array.length - 1 - i on every outer iteration.  

Note that a naive compiler might actually calculate that on each inner iteration in the original code.