 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Overloading Varargs Methods in Java
A method with variable length arguments(Varargs) can have zero or multiple arguments. Also, Varargs methods can be overloaded if required.
A program that demonstrates this is given as follows:
Example
public class Demo {    public static void Varargs(int... args) {       System.out.println("\nNumber of int arguments are: " + args.length);       System.out.println("The int argument values are: ");       for (int i : args)       System.out.println(i);    }    public static void Varargs(char... args) {       System.out.println("\nNumber of char arguments are: " + args.length);       System.out.println("The char argument values are: ");       for (char i : args)       System.out.println(i);    }    public static void Varargs(double... args) {       System.out.println("\nNumber of double arguments are: " + args.length);       System.out.println("The double argument values are: ");       for (double i : args)       System.out.println(i);    }    public static void main(String args[]) {       Varargs(4, 9, 1, 6, 3);       Varargs('A', 'B', 'C');       Varargs(5.9, 2.5);    } }  Output
Number of int arguments are: 5 The int argument values are: 4 9 1 6 3 Number of char arguments are: 3 The char argument values are: A B C Number of double arguments are: 2 The double argument values are: 5.9 2.5
Advertisements
 