• Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing array at cmd line  RSS feed

 
nirjari patel
Ranch Hand
Posts: 386
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we pass array as a cmd line argument as follows ?

>java TestRun file[], number

if yes, in the main(), how do we capture this array ?

public static void main(String [] args){
String [] files = args1 ;
// or will it be String [] files = args1[];
}

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only thing you can type into a command line is a string of text. The command line interpreter breaks the string at spaces (ignoring options that start with -) to give your main() an array of the values.

So with that in mind, what exactly do mean by "passing an array"? What data would the "array" contain? What is the purpose?
 
Campbell Ritchie
Marshal
Posts: 56541
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nirjari patel wrote:Can we pass array as a cmd line argument as follows ?

>java TestRun file[], number

if yes, in the main(), how do we capture this array ?

public static void main(String [] args){
String [] files = args1 ;
// or will it be String [] files = args1[];
}

Thanks
If you pass the file name as the first token, it would be
What you posted won't compile.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!