Scala | Repeated Method Parameters Last Updated : 29 Mar, 2019 Comments Improve Suggest changes Like Article Like Report In Scala, Repeated Method parameters are supported, which is helpful when we don't know the number of arguments a method requires. This property of Scala is utilized in passing limitless parameters to a method defined. Important points : The methods with Repeated Parameters should have each of the parameters of same type. A Repeated parameter is always the last parameter of the method defined. The method defined by us, can have only one parameter as Repeated Parameters. Example: Scala // Scala program of repeated // parameters // Creating object object repeated { // Main method def main(args: Array[String]) { // Creating a method with // repeated parameters def add(x: Int*) : Int = { // Applying 'fold' method to // perform binary operation x.fold(0)(_+_) } // Displays Addition println(add(2, 3, 5, 9, 6, 10, 11, 12)) } } Output: 58 In order to add any number of extra parameters, we need to put * mark after the type of the parameter being used. Some more examples of Repeated Parameters: An Array can be passed in the Repeated Parameter method. Example: Scala // Scala program of repeated // parameters // Creating object object arr { // Main method def main(args: Array[String]) { // Creating a method with // repeated parameters def mul(x: Int*) : Int = { // Applying 'product' method to // perform multiplication x.product } // Displays product println(mul(Array(7, 3, 2, 10): _*)) } } Output: 420 In order to pass an array in the defined method, we need to put a colon i.e, : and _* mark after passing the values in the array. An example to show that Repeated Parameters are always the last parameter of the method defined. Example: Scala // Scala program of repeated // parameters // Creating object object str { // Main method def main(args: Array[String]) { // Creating a method with // repeated parameters def show(x: String, y: Any*) = { // using 'mkString' method to // convert a collection to a // string with a separator "%s is a %s".format(x, y.mkString("_")) } // Displays string println(show("GeeksforGeeks", "Computer", "Sciecne", "Portal")) } } Output: GeeksforGeeks is a Computer_Sciecne_Portal Here, format is used to format strings. Comment More infoAdvertise with us Next Article Scala | Repeated Method Parameters N nidhi1352singh Follow Improve Article Tags : Scala Scala Scala-Method Similar Reads Parameterless Method in Scala Prerequisites - Scala | Functions A parameterless method is a function that does not take parameters, defined by the absence of any empty parenthesis. Invocation of a paramaterless function should be done without parenthesis. This enables the change of def to val without any change in the client cod 2 min read Implicit Parameters In Scala Implicit parameters are the parameters that are passed to a function with implicit keyword in Scala, which means the values will be taken from the context in which they are called. In simpler terms, if no value or parameter is passed to a method or function, then the compiler will look for implicit 2 min read Scala | Named Arguments In Scala when arguments passes through the function with a named parameters, we can label the arguments with their parameter names.These named arguments are cross matched with the named parameters of function. In normal scenario Unnamed Parameters uses Parameter Positions to make Function or Constru 3 min read Method Overriding in Scala Method Overriding in Scala is identical to the method overriding in Java but in Scala, the overriding features are further elaborated as here, both methods as well as var or val can be overridden. If a subclass has the method name identical to the method name defined in the parent class then it is k 8 min read Method Overloading in Scala Method Overloading is the common way of implementing polymorphism. It is the ability to redefine a function in more than one form. A user can implement function overloading by defining two or more functions in a class sharing the same name. Scala can distinguish the methods with different method sig 5 min read Like