File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Murach's Java Servlets and JSP this week in the Servlets 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: 18509
    
  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: 37943
    
  22
You can also write . . . but only if you keep the declaration and initialisation in the same statement.
 
jQuery in Action, 2nd edition
 
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