This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes array initialization? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "array initialization?" Watch "array initialization?" New topic
Author

array initialization?

harish shankarnarayan
Ranch Hand

Joined: Sep 12, 2005
Posts: 158
Example by Barry Sir,

this compiles fine can anyone explain me wat all r the possible ways we can initialize.

as per wat i knew , ifelt only thru " new " i can initialize arrays.
as per the example given above ,it it so trhat we can initialize arrays directly in the constructors as given above.
[ October 18, 2005: Message edited by: Barry Gaunt ]

Harish<br />SCJP 1.4 (85%)
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
HI..


int scores[]=new int[]{1,2};

or

int scores[]={1,2};


or

int scores[]=new int[2];

scores[0]=1;
scores[1]=2;


[ October 21, 2005: Message edited by: A Kumar ]
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
"as per wat i knew , i felt... "

Yes, but what does your Java book say?


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: array initialization?
 
Similar Threads
Array doubt
Two dimensional array
ExamCram Qts
I am a real JAVA beginner, please take a look at this code.
local variable creation