Java Program to Use Method Overloading for Printing Different Types of Array
In Java method overloading can be defined as the class containing multiple methods with the same name but the list of parameters or type of parameters or the order of the parameters of the methods should not be the same. We can print different types of arrays using method overloading in java by making sure that the method contains different parameters with the same name of the method.
Let’s implement a program with the printArray() method overloaded three times to print different types of array. And every time the function has different parameters. In the main method provide the required inputs to each array and then by calling their respective methods the array printed on the screen.
The Integer array is: 2 4 6 6 8 The Character array is: H E L L O The String array is: Ram Nidhi John Raju Sara The Double array is: 10.0123 89.123 65.132 78.321 1.798
Time Complexity: O(N), where N is the size of the array.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.