Array class sort(Object[] a, int fromIndex, int toIndex) method example
Array class sort(Object[] a, int fromIndex, int toIndex) method example. This example shows you how to use sort(Object[] a, int fromIndex, int toIndex) method.This method Sorts the specified range of the specified array of objects into ascending order, according to the natural ordering of its elements.
Here is the code:-
/**
* @Program that Sorts the specified range of the specified array of objects
* into ascending order, according to the natural ordering of its elements.
* sort13Array.java
* Author:-RoseIndia Team
* Date:-16-May-2008
*/
import java.util.*;
public class sort13Array {
public static void main(String[] args) {
//Creating a Object array
Object b[]={"ROSE","IN","ROHINI"};
// Sorts the specified range of the specified array of objects into
//ascending order, according to the natural ordering of its elements.
Arrays.sort(b,0,2);
//Displays the array
System.out.print("The array of bytes into ascending order is:-");
for(int i=0;i<b.length;i++)
System.out.print("\t"+b[i]);
}
} |
Output of the program:-
The array of bytes into ascending order is:- IN ROSE ROHINI |
|