Hello
I have a basic question, in my application i have 4 arguments to pass before running the application no i want to add new 5th argument but it should be optional. So how i can do this
i have something like this
public static void main(String args[])
{
if (args.length != 4 )
{
System.out.println();
System.out.println("Usage: <arg0> <arg1> <arg2> <arg3> ");
return;
}
String baseFolder = args[0];
String host = args[1];
String username = args[2];
String password = args[3];
Now i want to add 5th optional argument, means on comand line if i pass 4 paramenter then also it should work (when 5th is not provided), if 5th is provided then it should consider 5th argument
how this can be done
System.out.println("Usage: <arg0> <arg1> <arg2> <arg3><arg4> ");
String baseFolder = args[0];
String host = args[1];
String username = args[2];
String password = args[3];
String optional = args[4];
Thanks
String baseFolder = args[0];
String host = args[1];
String username = args[2];
String password = args[3];
String optional = null; // or set it to some default value you want it to be if its not passed
// if the 5th param is there, read it!
if (args.length == 5) {
optional = args[4];
}