public class SelectionSort {
  
  public int[] selectionSort(int[] array) {
    if (array == null || array.length <= 1) {
      return array;
    }
    for (int i = 0; i < array.length - 1; i++) {
      int min = i;
      for (int j = i + 1; j < array.length; j++) {
        if (array[j] < array[min]) {
          min = j;         
        }        
      }
      swap(array, i, min);
    }
    return array;
  }
    
  public void swap(int[] array, int left, int right) {
    int temp = array[left];
    array[left] = array[right];
    array[right] = temp; 
  }
    
  public static void main(String[] args) {
    SelectionSort solution = new SelectionSort();
      
    int[] array = null;
    array = solution.selectionSort(array);
      
    array = new int[] { 2, 4, 1, 5, 3};
    array = solution.selectionSort(array);
    
  }  
}
int i is used to be the first index of the rest array after each iteration
int j is used to store the min index in the each iteration 
int i is outer loop, int j is inner loop
After completing full circle of inner loop, then code goes to the outer loop