Home » Core Java » util » Arrays

Arrays

java.util.Arrays Example

In this example, we will show the range of functionality provided by the java.util.Arrays class. The Arrays class of the java.util package contains several static methods that you can use to compare, sort, and search in arrays. In addition, you can use this class to assign a value to one or more elements of an array. This class is a ...

Read More »

Compare two dimensional arrays

With this example we are going to demonstrate how to compare two dimensional arrays. We are using int arrays, but the same API applies to any types of arrays, e.g. boolean[][], byte[][], char[][], double[][], float[][], long[][], short[][] and String[][]. In short, to compare two dimensional arrays we have implemented a method as described below: The example’s method is boolean equal(final ...

Read More »

Sort arrays example

This is an example of how to sort arrays. We are using an int array in the example, but the same API applies to any type of arrays e.g. byte[], char[], double[], float[], long[], short[]. Sorting an int array implies that you should: Create an int array with elements. Invoke sort(int[] a) API method of Arrays . It sorts an ...

Read More »

Binary search Java array example

In this example we shall show you how to search an element of an array using the binary algorithm in Java. We are using an int array in the example, but the same API applies to any type of arrays e.g. byte[], char[], double[], float[], long[], short[]. We are using the binarySearch(int[] b, int value) API method of Arrays. To ...

Read More »

Convert Object Array to List example

With this example we are going to demonstrate how to convert an Object array to a List. We are using a String array in the example. In short, to convert an String array to a List you should: Create a String array with elements. Invoke asList(Object[] objArray) API method of Arrays, with the list as parameter. It returns a fixed ...

Read More »