• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Transfer command line args[] to String array

 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
the correct assignment statement at line 5 is
String s[] = args;
Also this does not mean copying args to s.
thks,
Chinmay.
 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You need to remove the brackets from args[] in that statement. It should look like this:
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
We're all out of roofs. But we still have tiny ads:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic