Java-copyOf

copyOf The copyOf() method returns a copy of an array and has the following forms : The original array is specified by source, and the length of the copy is specified by len. If the copy is longer than source, then the copy is padded with zeros, nulls or false. If the copy is shorter … Read more…

Java-arraycopy

arraycopy The arraycopy( ) method can be used to copy quickly an array of any type from one place to another. This is much faster than the equivalent loop written out longhand in java. Program  Program Source public class Javaapp { public static void main(String[] args) { int[] array_v1 = {10,20,30,40,50,60}; int[] array_v2 = new int[4]; … Read more…

Java-Character Array

Character Array The character array is a data structure that stores a collection of character values of the char type. The character array is equivalent to the integer array. The character representation consists of a list of the array’s elements, enclosed in braces (“{}”). Adjacent elements are separated by the characters ‘,’. Program Program Source … Read more…

Java-Convert Integer Array to String

Convert Integer Array to String There is an even easier way to convert integer array to String, using the toString method of the Arrays class. The call Arrays.toString(array) returns a string containing the array elements, enclosed in brackets and separated by commas, such as “[20,40,60,80,90]”. Program Program Source import java.util.Arrays; public class Javaapp { public … Read more…

Java-Get Array Values Using For-Each

Get Array Values Using For-Each Loop The for each loop helps us to retrieve the array of elements efficiently rather than using array indexes. This loop is designed to cycle through the entire array, obtaining one element at a time, in sequence, from beginning to end. The loop traverses the elements of the array, not … Read more…

Java-Write Array Values Using Loop

Write Array Values Using Loop We shall use a for loop for providing the values of the elements of an array as input data. For example, in the following program, the array_v1 array size is 5. The values of its elements shall be fed in by using for loop. The values are then retrieved from … Read more…