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
posted
0
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
posted
0
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
posted
0
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...
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