Posts

Showing posts with the label Autoboxing

Quick Refresh : JDK1.5 New Feature

Variable Argument (Varargs):  The varargs allows the method to accept zero or multiple arguments. Before varargs either we use the overloaded method or take an array as the method parameter but it was not considered good because it leads to the maintenance problem. If we don't know how many arguments we will have to pass in the method, varargs is the better approach. The advantage of Varargs is that we don't have to provide overloaded methods so less code. Rules for varargs:  While using the varargs, you must follow some rules otherwise program code won't compile. The rules are as follows: There can be only one variable argument in the method. Variable argument (varargs) must be the last argument. Syntax of varargs:  The varargs uses ellipsis i.e. three dots after the data type.  return_type method_name(data_type... variableName){} void method(String... a, int... b){}//Compile time error void method(int... a, String b){}//Compile time error cl...