aspose file tools
The moose likes Beginning Java and the fly likes Transfer command line args[] to String array Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Transfer command line args[] to String array" Watch "Transfer command line args[] to String array" New topic
Author

Transfer command line args[] to String array

Thomas Markl
Ranch Hand

Joined: Mar 08, 2001
Posts: 192
Hello,
I want to transfert command line args[] to String array:
public class Test114 {

public static void main(String args[]) {

String s[] = args[];
if (s.equals(null))
{
System.out.println("s is null");
}else
{
System.out.println("s is not equal");
}
}
}
I get this compiler error:
C:\Java\EigeneJavaProgramme>javac Test114.java
Test114.java:5: '.class' expected
String s[] = args[];
^
Test114.java:5: cannot resolve symbol
symbol : class args
location: class Test114
String s[] = args[];
^
Test114.java:5: unexpected type
required: value
found : class
String s[] = args[];
^
3 errors
Whats the mistike in line 5?
Thanks
Thomas
Chinmay Bajikar
Ranch Hand

Joined: Dec 08, 2001
Posts: 159
hi,
the correct assignment statement at line 5 is
String s[] = args;
Also this does not mean copying args to s.
thks,
Chinmay.


The strength of the Wolf is the pack & the strength of the pack is the wolf....Rudyard Kipling
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331

You need to remove the brackets from args[] in that statement. It should look like this:


Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
The only way s will be null is if args is null. I don't think args is ever null. If there are no command line arguments args is an array of length 0. Of course, I may be incorrect about this...


Java API Documentation
The Java Tutorial
Robbie shi
Greenhorn

Joined: Jan 05, 2003
Posts: 28
String [] s=args[] //it's wrong~~
String [] s=arg; //that didnt copy Array arg to
s
i prefer to use a loop to copy element from one
array to another
---
Robbies
-----------------------------
1.java IDE tool : JawaBeginer
2.Java Jar tool : JavaJar
http://www.pivotonic.com
 
I agree. Here's the link: http://zeroturnaround.com/jrebel
 
subject: Transfer command line args[] to String array
 
Similar Threads
Null and NullPointers with "==" and ".equals()"
help with running dos commands using java
constructor
what does this means while((s+ss) == null) ?
using getopt() in Java