This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes int[] foo = new int[]{1, 2, 3} What does it mean? 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 » Java » Beginning Java
Bookmark "int[] foo = new int[]{1, 2, 3} What does it mean?" Watch "int[] foo = new int[]{1, 2, 3} What does it mean?" New topic
Author

int[] foo = new int[]{1, 2, 3} What does it mean?

You Gin
Ranch Hand

Joined: Jul 23, 2010
Posts: 52
Can you guys "pronounce" me this statement? I just can't understand it. Thanks in advance.

int[] foo = new int[]{1, 2, 3}
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18914
    
  40


You are declaring an int array named foo. And then assigning it to an new instance of the int array, with 3 elements, as listed.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
W. Joe Smith
Ranch Hand

Joined: Feb 10, 2009
Posts: 710
You are creating a new int array object, called foo, and assigning teh values 1,2,3 to the array.


SCJA
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
You Gin
Ranch Hand

Joined: Jul 23, 2010
Posts: 52
Ok, sounds clear. Thank you.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
You can also write . . . but only if you keep the declaration and initialisation in the same statement.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: int[] foo = new int[]{1, 2, 3} What does it mean?