Java Program to Use Method Overloading for Printing Different Types of Array Last Updated : 30 Mar, 2023 Comments Improve Suggest changes Like Article Like Report 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. Implementation: Java // Java Program to Use Method Overloading // for Printing Different Types of Array class methodOverloadingDemo { // creating a method for printing integer // array with integer parameter public static void printArray(Integer[] arr) { System.out.println("The Integer array is: "); // for loop for printing the elements of array for (Integer i : arr) System.out.print(i + " "); System.out.println(); } // overloading the above created method with different // parameter method contains a character parameter public static void printArray(Character[] arr) { System.out.println("\nThe Character array is: "); // for loop for printing the elements of array for (Character i : arr) System.out.print(i + " "); System.out.println(); } // now the parameter for the overloaded method is String public static void printArray(String[] arr) { System.out.println("\nThe String array is: "); // for loop for printing the elements of array for (String i : arr) System.out.print(i + " "); System.out.println(); } // now the parameter for the overloaded method is double public static void printArray(Double[] arr) { System.out.println("\nThe Double array is: "); // for loop for printing the elements of array for (Double i : arr) System.out.print(i + " "); } // main function public static void main(String args[]) { // calling the parameters of all the // methods and taking the inputs Integer[] iarr = { 2, 4, 6, 6, 8 }; Character[] carr = { 'H', 'E', 'L', 'L', 'O' }; String[] sarr = { "Ram", "Nidhi", "John", "Raju", "Sara" }; Double[] darr = { 10.0123, 89.123, 65.132, 78.321, 1.798 }; // calling the methods and printing the arrays printArray(iarr); printArray(carr); printArray(sarr); printArray(darr); } } OutputThe 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. Auxiliary space: O(1) because constant variables have been used Comment More infoAdvertise with us Next Article Java Program to Use Method Overloading for Printing Different Types of Array N neelutiwari Follow Improve Article Tags : Java Technical Scripter Java Programs Technical Scripter 2020 Java-Array-Programs +1 More Practice Tags : Java Similar Reads Java Program to Print the Elements of an Array An array is a data structure that stores a collection of like-typed variables in contiguous memory allocation. Once created, the size of an array in Java cannot be changed. It's important to note that arrays in Java function differently than they do in C/C++As you see, the array of size 9 holds elem 6 min read Simplest Method to Print Array in Java Arrays.toString() Method of java.util.Arrays class is the simplest method to print an array in Java. This method takes an array as a parameter and returns a string representation of the array and it can work with all types of arrays like integer arrays, string arrays, etc.Example:Java// Java Program 1 min read How to Override toString Method for ArrayList in Java? Every class in java is a child of Object class either directly or indirectly. toString() is present in Object class. The toString method returns a string representation of an object. The toString() can be overridden as part of a class to cater to the customized needs of the user. Whenever we try to 2 min read How to do Method Overloading for Null Argument? In Java, Method overloading is a process in which we can define a method with the same name but with a different parameter in the same class. This is a feature of OOP (object-oriented programming). It helps increase the readability of the code, as we can use the same name for a function performing t 3 min read Program to convert Primitive Array to Stream in Java An array is a group of like-typed variables that are referred to by a common name. An array can contain primitives data types as well as objects of a class depending on the definition of the array. In case of primitives data types, the actual values are stored in contiguous memory locations. In case 3 min read Like