-3

Peace and blessing be upon you.

Say I have:

int[] array = {1,3,5,2,9,7,0};

Simply wanna sort this as:

{0,1,2,3,5,7,9};
jaksdfjl
  • 115
  • 3
  • 9

3 Answers3

0

Try,

int[] array = {1,3,5,2,9,7,0};
Arrays.sort(array);

You will need to import java.util.Arrays

Robert
  • 287
  • 1
  • 9
0

use Arrays class of collection framework

import java.util.Arrays;
class TestArray {
public static void main(String arg[]) {
int[] array = {1,3,5,2,9,7,0};
System.out.println("before sort : "+Arrays.toString(array));    
Arrays.sort(array);
System.out.println("after sort"+Arrays.toString(array));    

}
}
Mohsin AR
  • 2,998
  • 2
  • 24
  • 36
-1

Use the Arrays class :

Arrays.sort(array);

:-)

Aurasphere
  • 3,841
  • 12
  • 44
  • 71
Geek
  • 23,089
  • 20
  • 71
  • 85