1

Suppose, if we have to pass two values from terminal to a java program, value will be treated as String in program. What if the values are spaces. How do we pass them without any need to treat them separately inside the program?

AN_SH
  • 217
  • 2
  • 7
  • 16

3 Answers3

2

Use quotation marks to wrap your arguments so that the shell you are using does not interpret them as separate arguments.

ferahgo
  • 408
  • 1
  • 4
  • 11
  • Will passing the space in quotation require extra processing in the program? or it will take value as with quotation? – AN_SH Jan 23 '17 at 20:36
  • No, it will take the value that is within the quotes. You must escape the quotes if you want to pass them into the program as an argument. – ferahgo Jan 23 '17 at 21:18
1

You answered your own question in response to Saagar Jha in your question's comment's section.

java MyApp " "

Simply enclose the space character between two double-quotes to pass it to your app's main method.

nasukkin
  • 2,460
  • 1
  • 12
  • 19
  • if I am passing it that way, then won't the program require extra processing to remove the quotes? – AN_SH Jan 23 '17 at 20:42
0

You want to pass argument values which contains only whitespaces?

Just pass the whitespaces between "".

For example here : java yourProgram " " " " you pass two arguments (each one is a whitespace)

davidxxx
  • 125,838
  • 23
  • 214
  • 215