How to sort an array in Java? -


this have tried, wrong!

public static int[] sortit(int[] array){     int temp = 0;      for(int index =0; index<array.length; index++){      for(int i=0; i<array.length; i++){         if(array[index]<array[i]){             temp = array[i];             array[0] = array[i];             array[index] = temp;         }         }     }     return array; } 

why not just

arrays.sort(array); 

see http://docs.oracle.com/javase/7/docs/api/java/util/arrays.html#sort(int[])


Comments