Possible sub-optimal selection sort Why is this code "bad"? In all of the selection sort codes I am learning from, they do it much differently. I will learn the proper code from the book, but I would love to know why this particular code is bad.

public class Main {
    public static void main(String[] args) {
        int[] array = {8, 3, 5, 7, 9, 2, 4, 6, 8, 0};
        System.out.println("The sorted array is: ");
        displayArray(selectionSort(array));
    }

    public static int[] selectionSort(int[] list) {
        int[] result = list;

        for (int i = 0; i &lt; result.length - 1; i++) {
            for (int j = i + 1; j &lt; result.length; j++) {
                if (result[i] &gt; result[j]) {
                    int temp = result[i];
                    result[i] = result[j];
                    result[j] = temp;
                }
            }
        }
        return result;
    }

    public static void displayArray(int[] list) {
        for (int i = 0; i &lt; list.length; i++) {
            if ((i + 1) % 5 == 0)
                System.out.println(list[i]);
            else
                System.out.print(list[i] + " ");
        }
    }
}
Too many swaps
The &quot;standard&quot; selection sort finds the minimum element and swaps the first element with the minimum element once per loop. In total there should be N swaps. Your version of selection sort can swap up to (N^2)/2 times.
Unnecessary variable
I'm not sure why you use the variable result and return it.  You can just operate on the array that is passed in (list) directly.  When I first read your code I thought you were making a copy of the array, because you had this extraneous variable.
The &quot;standard&quot; selection sort
Here is an example of a &quot;standard&quot; selection sort:
public static void selectionSort(int[] list)
{
    int len = list.length;
    for (int i = 0; i &lt; len - 1; i++) {
        int smallestIndex = i;
        int smallestValue = list[i];
        for (int j = i + 1; j &lt; len; j++) {
            if (list[j] &lt; smallestValue) {
                smallestIndex = j;
                smallestValue = list[j];
            }
        }
        if (smallestIndex != i) {
            list[smallestIndex] = list[i];
            list[i] = smallestValue;
        }
    }
}