Methods Allow Variable-Length Parameter Lists

Varargs. Yes, that is what passes for a word these days (did you ever read Ray Bradbury's “The Sound of Thunder”?). The vararg is a thing that they have in C# and other languages and it means that you stomp your foot and say, “This method has a bunch of parameters and I just don't know how many parameters a client might want to pass it, all right?” It means “variable length argument list.”

This is an easy concept to start working with. The following class defines a method that accepts a vararg, and invokes the same method passing it first several arguments and then fewer arguments. The arguments come in as an array.

 package net.javagarage.varargs; /* Demos how to use variable length argument lists. ...

Get Java Garage now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.