In this post under Java, I will show with example how to check whether two arrays are equal or not. The class Arrays under java.util package has “equals” static method which takes two arrays as arguments and compare their contents to check whether they are same. Below is the code showing an example Main 1…… Continue reading Comparing two arrays for equality
Category: Collections
Sorting a section of an array
In this post I will explain how to sort a section of an array. The java Arrays class provides a static method named “sort” which takes the below three arguments 1) the array 2) fromIndex 3) toIndex This method sorts a section of the array. The section to be sorted is indicated by fromIndex (position…… Continue reading Sorting a section of an array
Sorting arrays using Comparator
This post explains how to sort arrays using comparator with an example. The java jdk provides Arrays class, which has a static method named “sort”. This method takes two arguments 1) the array to be sorted 2) Comparator which contains the logic to sort the array Below is the example which sort cards based on…… Continue reading Sorting arrays using Comparator
Different ways to convert list to array
This post explains two ways through which we can convert a list to array. First approach is simply calling toArrayList on list instance. This method returns an Object array, When converting to array it doesn’t consider the data type of the entries in the list. Below is the code snippet list.toArray(); The second approach involves…… Continue reading Different ways to convert list to array