What does the method sort(obj[] a, int fromIndex, int toIndex) do in java?
The java.util.Arrays.sort(Object[] a, int fromIndex, int toIndex) method sorts the specified range of the specified array of objects into ascending order, according to the natural ordering of its elements. The range to be sorted extends from index fromIndex, inclusive, to index toIndex, exclusive.
Example
import java.util.Arrays;
public class ArrayDemo {
public static void main(String[] args) {
Object ob[] = {27, 11, 5, 44};
for (Object number : ob) {
System.out.println("Number = " + number);
}
Arrays.sort(ob, 1, 3);
System.out.println("Object array with some sorted values(1 to 3) is:");
for (Object number : ob) {
System.out.println("Number = " + number);
}
}
}
Output
Number = 27
Number = 11
Number = 5
Number = 44
Object array with some sorted values(1 to 3) is:
Number = 27
Number = 5
Number = 11
Number = 44
Published on 16-Jan-2018 11:02:00
- Related Questions & Answers
- What does the method fill(obj[], int fromIndex, int toIndex, int val) do in java?
- What does the method sort(int[] a, int fromIndex, int toIndex) do in java?
- What does the method removeRange(int fromIndex, int toIndex) do in java?
- What does the method fill(int[], int fromIndex, int toIndex, int val) do in java?
- What does the method set(int, obj o) do in java?
- What does the method sort(int[] a) do in java?
- What does the method fill(int[], int val) do in java?
- What does the method copyOfRange(int[] original, int from, int to) do in java?
- What does the method equals(int[] a1, int[] a2) do in java?
- What does the method copyOf(int[] original, int newLength) do in java?
- What does the method sort(obj[] a) do in java?
- What does the method hashCode(int[] a) do in java?
- What does the method int capacity() do in java?
- What does the method get(int) do in java?
- What does the method remove(int) do in java?