array java example

Sorting array elements sort() Comparator

The earlier sort() example sorts implicitly in natural ascending order. The order can be customized with the overloaded sort() method that takes a Comparator object as parameter. Two methods exist for sorting array elements with Arrays class. Following are the method signatures. static void sort(int array1[]): Sorts all the elements…

Filling array elements fill() method

Arrays.fill() is useful to fill an array with one value. After this method call, all the elements of the array will have the same value. Two methods exist to do the job with Arrays class; the first one fills all the array elements and the second one fills a few…