Arrays

Removing Duplicates Array Java

Removing Duplicates Array Java Summary: Java is so developed by Designers to write code easily for Developers. Forget the laborious days of C/C++ coding. This tutorial "Removing Duplicates Array Java" is the place to prove it. It is a general and interesting code for beginners and this can be achieved…

Sort part array elements sort()

On sorting of array elements, three important and often used methods exist with Array class. They are discussed in this tutorial "Sort part array elements sort()" in easy terms, example and screenshot. Sorting array elements with sort() Sorting array elements with sort() and Comparator Sorting few array elements with sort()…

Java Shuffle Array shuffle()

Java collections framework comes with two classes Collections and Arrays (from java.util) to operate on the elements of collection classes (data structures) and arrays. To shuffle the elements of a data structure, the Collections class includes a method shuffle() but Arrays class does not come with one. To shuffle the…

Sorting complete array elements sort()

Arrays.sort() method sorts all the array elements in ascending order. It avoids writing tedious sorting algorithms. Two methods exist with Array class for sorting. Following are the method signatures. static void sort(int array1[]): Sorts all the elements of the array array1 in ascending numerical order. The sorting algorithm used is…

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…

Compare arrays equality equals()

Arrays.equals() method compares two arrays and tests whether they have the same elements are not. Returns a boolean value of true if they come with the same elements else false. Here, both arrays should have the same elements in the same order. If the order changes, the method returns false…

Convert array to List with asList()

Arrays.asList() converts all the elements of the array into a List. It is the easiest way to pass the elements of an array to a List; an interoperability feature between arrays and collections framework classes. Convert array to List with asList() Following is the method signature static List asList(T array):…

Get hashcode with hashCode()

About Hashcode Generally, a programmer writes a lengthy for loop to compare two strings for their equality, checking each character in both the strings. It is a time consuming process and performance goes down especially when the strings are lengthy. To overcome this, Java designers introduced hash code. It is…

Search array element binarySearch()

Arrays.binarySearch() method is useful to find out the index number of an element in the array. Two methods exist in the Arrays class for the purpose and following are their method signatures static int binarySearch(int array1[], int searchNum): Searches the element searchNum in the array array1. This method should be…

class Arrays API Methods

We have seen how Collections class methods made Java Programmer job easy to operate on data structure elements and we have discussed nearly 25 operations like comparing, sorting and searching etc. with good example codes. Now it is the turn with Arrays class. Almost the same methods exist with Arrays…

Printing array elements with toString()

Arrays.toString() method makes it easier to print the elements of an array, forgetting the tedious iteration with for loops. Following is the method signature static String toString(int array1[]): Returns the array in string form useful to be displayed in a text field. This display the array elements comma-separated and placed…