Well, There are different ways you can sort your different types of array , i.e. whether int[] , byte[], sort[], String[]
or any anoher type of array
(custome java object array). In this post, I tried to demonstrate primitive types array sorting by using in-built utility tool i.e. java.util.Arrays
class. Or if you have primitive types of array of string, then how can you sort by using java.util.Arrays
utility class in java.
There are different overloaded method available in java.util.Arrays
utility class, which can turn your job easy in day to day life of project development. Overloaded methods are as :
Arrays.sort (byte []) Arrays.sort (short []) Arrays.sort (int []) Arrays.sort (String []) Arrays.sort (float []) Arrays.sort (double []) Arrays.sort (long []) Arrays.sort (Object [])
By default, all the above methods sort in natural ascending order.
Sorting of String arrays
String[] fruits = {"mango", "banana", "apple"}; // sorting by using java.util.Arrays utility class Arrays.sort(fruits); // display sorted string arrays. System.out.println("sorted fruit Arrays: " + Arrays.toString(fruits));
Output:
sorted fruit Arrays: [apple, banana, mango]
Your suggestions are welcome to encourage and improve the post. Happy Learning! 🙂