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 of Objects

Array of Objects An array of object is a data structure that holds a group of object. For example : Data[] obj = new Data[3]; This statement creates the array which can hold references to three Data objects. In this case, create an object for each of the null objects. Notice that we have to … Read more…

Java-Variable Length Arguments(Method Overloading)

Variable Length Arguments (Method Overloading) Just like normal methods, java  provides facility to overload vararg methods also. You can overload a method with a variable length arguments as long as the parameters for the methods differ in type or order. For example : void varArgsTest(int…v){} void varArgsTest(boolean…v){} void varArgsTest(String…v){} The types of its varargs parameter can … Read more…

Java-Variable Length Arguments

Variable Length Arguments If you don’t know how many argument we will have to pass in the method, varargs[Variable-Length Arguments] is the easy approach. Using this technique you can send as many as parameters of the same type without any restriction. For example, in the following program, inside varArgsTest( ), v is operated on as an … Read more…