Skip to main content

Posts

Showing posts with the label Customized Sorting Of Arrays

Simplest Way to Sort an array in Java and Customized Sorting Of arrays in java

 Simplest Way to Sort an array in Java and Customized Sorting Of arrays in java Do Check My Video On Utility Classes: Arrays: Arrays class is the utility class to define the several utility methods for the array objr=ect Array class defines the following methods to sort the array 1)public static void sort(Primitive[] P): to sort acc. to natural sorting order 2)public static void sort(Object[] P): 3)public static void sort(Object[] o,Comparator c): sort acc to customized sorting order Example: import java.util.Arrays; import java.util.Comparator; public class Test{     public static void main(String[] args) {         int[] a = {10,5,20,11,6};         System.out.println("Primitive array before sorting: ");         for(int a1:a){             System.out.print(""+a1+" ");//10 5 20 11 6         }         Arrays.sort(a);         System.out.println();         System.out.println("Primitive array after Sorting : ");         for(int a1:a) {             Syst