1

What is the maximum size of String args[] in Java?

More specifically, how many command line parameters (as String elements) can args[] accommodate - i.e. how many strings can I pass via the command line after java Main?

Like, java main hi hello how r you I m fine. What is the limit?

pushkin
  • 9,575
  • 15
  • 51
  • 95
Astitva S.
  • 21
  • 6
  • 3
    but also depends on OS (I think) – user85421 Jun 27 '18 at 14:59
  • @CarlosHeuberger is right, e.g : https://stackoverflow.com/questions/3205027/maximum-length-of-command-line-string – Arnaud Jun 27 '18 at 15:00
  • Yes, it is possible that the OS Command shell may impose limits, so the smaller of the JVM's limit and the OS Command shell would be right. I think it's highly unlikely that any reasonable application command line should reach 64K – Dragonthoughts Jun 27 '18 at 15:02
  • 1
    Integer.MAX_VALUE , comes around 2 billion – Narayan Jun 27 '18 at 15:03
  • As it comes down to **C's main**: there is no limit specified. I would also advise to support in such a case the Unix convention of having args is a file, say `argsfile.txt`, and pass a parameter `@argsfile.txt`. – Joop Eggen Jun 27 '18 at 15:03

0 Answers0