Java-Returning Arrays From Method

Returning Arrays From Method A method may also return an array. For example, in the following program, the method returnData( ) returns an array. Program Program Source class Data { int[] returnData() { return new int[]{20,40,60,80}; } } public class Javaapp { public static void main(String[] args) { Data da = new Data(); int[] getData = da.returnData(); for(int … Read more…

Java-Array as Parameters of Method

Array as Parameters of Method By passing the array name, we are, in fact passing the reference of the array to the called function. The array in the called function now refers to the same array stored in the memory. Program Program Source class Setdata{ void setData(int[] v) { v[0] = 10; v[2] = 30; v[4] … Read more…

Java-Array of String

Array of String You can place objects of string into arrays. This is done in the same way as for character. The string representation consists of a list of the array’s elements, enclosed in braces (“{}”). Adjacent elements are separated by the string”,”. Program Program Source public class Javaapp { public static void main(String[] args) … Read more…

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…