In java in args you need to pass a string with spaces in one parameter, how to do this? And in general, is it possible or args understands the parameters by split ("")?

  • It does not depend on java, but on the shell in which you run the program. Try something like java com.example.SomeClass "arg1-part1 arg1-part2 arg1-part3" arg2 arg3 - Sergey Gornostaev
  • Thank. It really is so trite. )) Everything turned out, it was enough quotes, somehow did not immediately guess. - vinsler

1 answer 1

This is due to the fact that the space character separates the command line arguments. To interpret the string with spaces as one argument, enclose it in quotes.

For example:

 java Echo "Drink Hot Java" Drink Hot Java 

The Java ™ Tutorials - Command-Line Arguments