Wednesday, November 22, 2017

JAVA - How to sort array elements

For sorting array elements use class java.util.Arrays. This class contains static methods for working with arrays.
String[] array = { "One", "Two", "Three", "Four", "Fight" };

Arrays.sort( array );

System.out.println( Arrays.toString( array ) );
The output is:
[Fight, Four, One, Three, Two] 
NOTE: This is the most simplest variant of array sorting.

No comments:

Post a Comment