tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Java > Core > Arrays > Arrays Sort

Arrays Sort 

The following example shows how to sort any given array using Arrays.sort() API.

File Name  :  
com/bethecoder/tutorials/utils/arrays/ArraysSort.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.utils.arrays;

import java.util.Arrays;

public class ArraysSort {

  public static void main (String [] args) {
    
    int [] intArray = 7861429};
    System.out.println("Before sort : " + Arrays.toString(intArray));
    
    Arrays.sort(intArray);
    System.out.println("After sort : " + Arrays.toString(intArray));
    
    System.out.println();
    
    char [] chrArray = 'b''e''t''c''o''d''e''r' };
    System.out.println("Before sort : " + Arrays.toString(chrArray));
    
    Arrays.sort(chrArray);
    System.out.println("After sort : " + Arrays.toString(chrArray));
  }
}
   

It gives the following output,
Before sort : [7, 8, 6, 1, 4, 2, 9]
After sort : [1, 2, 4, 6, 7, 8, 9]

Before sort : [b, e, t, c, o, d, e, r]
After sort : [b, c, d, e, e, o, r, t]


                    Print

   



Books Recommendation

 
 
bl  br