Posted By

nulldev on 02/18/15


Tagged

sort java array arrays example int


Versions (?)

Java Arrays.sort() Example


 / Published in: Java
 

URL: http://www.tutorialspoint.com/java/util/arrays_sort_int.htm

An example of the Arrays.sort() function. Taken from: http://www.tutorialspoint.com/java/util/arrayssortint.htm

  1. import java.util.Arrays;
  2.  
  3. public class ArrayDemo {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. // initializing unsorted int array
  8. int iArr[] = {2, 1, 9, 6, 4};
  9.  
  10. // let us print all the elements available in list
  11. for (int number : iArr) {
  12. System.out.println("Number = " + number);
  13. }
  14.  
  15. // sorting array
  16. Arrays.sort(iArr);
  17.  
  18. // let us print all the elements available in list
  19. System.out.println("The sorted int array is:");
  20. for (int number : iArr) {
  21. System.out.println("Number = " + number);
  22. }
  23. }
  24. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: EdwardWilson on August 9, 2018

Nice example bro. Thanks.

Cheers, http://www.flowerbrackets.com/java-sort-array/

You need to login to post a comment.