File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes when are the braces used {} Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "when are the braces used {}" Watch "when are the braces used {}" New topic

when are the braces used {}

Natraj Gudla
Ranch Hand

Joined: Feb 09, 2003
Posts: 34
I am working with a URL and URLCLassLoader , in one of the code blocks i have seen
URL[] urlObj = new URL[] {anotherurlobject};
Now what does this mean,
what is this form of declaration using the '{}' braces..
The Jav docs do not speak of any thing of this sort in the URL class...
Is this used for only URL class or we can use it where ever we use an array of objects..
can anyone help me?..
[ July 28, 2003: Message edited by: Natraj Gudla ]
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Curly braces are used to initialize an array in this instance. The line:

Creates an array of URL with a single element urlObj[0] which is equal to anotherurlobject.

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
I agree. Here's the link:
subject: when are the braces used {}
It's not a secret anymore!