This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund 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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Array Initialization" Watch "Array Initialization" New topic
Author

Array Initialization

sentil kumar
Ranch Hand

Joined: Oct 23, 2006
Posts: 74
int [] a1;
a1= {2,2,2};
why the above is not compiled. but the below code works fine.
a1= new int[]{2,2,2};
Sanjeev Singh
Ranch Hand

Joined: Nov 01, 2006
Posts: 381
Sentil,
Rather than asking why?Just burn that for the array creation by using syntax

The array declaration ,creation(on the fly... there is no new operator) and initialization can not be separated out.You can not image an object like {2,2,2} which is to be refered by a1 and for

The array declaration may be separated out from the creation and initilization but the creation and initialization can not be separated out.


~Sanjeev Singh<br />SCJP 1.5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Array Initialization
 
Similar Threads
array declaration
what is your blood group?
Dans Array Questions
arrays
arrays