File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Arrays" Watch "Arrays" New topic
Author

Arrays

Tanuja Vaid
Ranch Hand

Joined: Mar 07, 2002
Posts: 51
which of the following statements will correcly create and initialize an array of Strings to non null elements?(jq+ question)
why is
String[]SA=new String[1]{"aaa"};
not valid
and
String[]SA=new String[1];SA[0]="aaa";
valid
Also, I don't understand how below two options are valid too.
String[]SA={"aaa"};
String[]SA={new String("aaa")};
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Hello,
Just to point out the obvious...
The first one won't compile - so, it's not the right choice.
The other three will compile and do what the question is looking to do.
Bradley Kjell has a nice on-line Java tutorial that explains many concepts of Java step-by-step. Chapter 46 on Arrays might help you to understand array declaration and initialization better.
Good Luck,
-Dirk Schreckmann
[ March 07, 2002: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Hello,
One more source of good information...
From the horse's mouth:
http://java.sun.com/docs/books/tutorial/java/data/arrays.html
Good Luck,
-Dirk Schreckmann
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Arrays