Sorting of Array in java using java.util.Arrays

Connect with

Sorting of Array in Java using java.util.ArraysLearn sorting of Array in Java using java.util.Arrays class. Sorting of Object array, sorting of String array, sorting of int array, sorting of double array etc.

1. Overview of Sorting of Array in Java

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.

2. different types of Arrays for sorting

There are different overloaded methods available in java.util.Arrays utility class, which will be helpful and in-turns 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.

3. Sorting of String arrays

String[] fruits = {"mango", "banana", "apple"};

	// sorting by using java.util.Arrays utility class
	// display sorted string arrays.
	System.out.println("sorted fruit Arrays: " + Arrays.toString(fruits));

Output of sorting Arrays as::

sorted fruit Arrays: [apple, banana, mango]

4. Reference

I hope you enjoyed this post of sorting of different types of java.util.Arrays, and you can visit data structures and algorithms tutorial for more details

Visit Oracle Java docs for more details.
Your suggestions are welcome to encourage and improve the post. Happy Learning! 🙂

Connect with

Leave a Comment

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