This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android 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: 18538
    
  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: 38033
    
  22
You can also write . . . but only if you keep the declaration and initialisation in the same statement.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: int[] foo = new int[]{1, 2, 3} What does it mean?
 
Similar Threads
about gc()
problem in when to use this in java
instanceOf explanation needed
Loading 2-dimensional array with values
static method invocation problem