Sorting Arrays in Java

java.util.Arrays class has a sort method that can be used to sort an array of primitives or objects that implement the Comparable interface in the ascending order.

This method sorts characters by their ASCII codes, therefore, numbers will come first, then uppercase letters followed by lowercase letters.

For example, consider the following code.

		var arr = new String[] { "A", "a", "1" };

This code prints [1, A, a] because 1 is a number, ‘A’ is in upper case and ‘a’ in lower case.

For more information, visit this page.

Leave a Reply

Your email address will not be published. Required fields are marked *