Arrays.sort(): The class java.util.Arrays have many methods, one of these methods is the sort(), this method doesn’t return any value !
Syntax :
public static void sort(int[] arr, int from_Index, int to_Index)
arr - the array to be sorted
from_Index - the index of the first element, inclusive, to be sorted
to_Index - the index of the last element, exclusive, to be sorted
In the next example we will show you how to sort an array of integers in ascending order ?
import java.util.Arrays;
public class SortArrayClass
{
public static void main(String[] args)
{
// Our arr contains 8 elements
int[] arrays = {12, 8, 6, 45, 27, 3, 141};
Arrays.sort(arrays);
System.out.printf("Modified arrays[] : %s",
Arrays.toString(arrays ));
}
}
Output :
Modified arrays[] : [3, 6, 8, 12, 27, 45, 141]
read also : How to find duplicate elements in a Stream (Java 8) ?