| Author |
Array Declaration doubt
|
saloni jhanwar
Ranch Hand
Joined: Feb 09, 2012
Posts: 583
|
|
it works when i write
but i want this in one line ? any idea ?
|
Tell the difficulties that i am difficult.
|
 |
Thakur Sachin Singh
Ranch Hand
Joined: Jun 15, 2010
Posts: 209
|
|
|
in java we can return only class type value with return keyword.
|
my blog SCJP 6- 91%, IBM DB2, IBM RAD Certified
|
 |
Matthew Brown
Bartender
Joined: Apr 06, 2010
Posts: 3793
|
|
saloni jhanwar wrote:
Here you're trying to declare a variable and return it on the same line. You can't do that, but fortunately you don't need to - there's no need for the variable as you can just create the array and return it immediately. However, because you don't have an array declaration, you need to tell the compiler what kind of array to create. So:
|
 |
saloni jhanwar
Ranch Hand
Joined: Feb 09, 2012
Posts: 583
|
|
Matthew Brown wrote:
saloni jhanwar wrote:
Here you're trying to declare a variable and return it on the same line. You can't do that, but fortunately you don't need to - there's no need for the variable as you can just create the array and return it immediately. However, because you don't have an array declaration, you need to tell the compiler what kind of array to create. So:
Thanks Metthew
|
 |
gurpeet singh
Ranch Hand
Joined: Apr 04, 2012
Posts: 867
|
|
ya would just like to supplement Matthew's answer. You can do it in the following way as told by Mathew
This is called ANONYMOUS ARRAY CREATION in java. It is like creating an array JUST IN TIME without assigning it to any variable. beware though of the syntax
//here we have declared size between the rectangular braces
So watch out for code like this.
|
OCPJP 6(100 %) OCEWCD 6(91 %)
|
 |
 |
|
|
subject: Array Declaration doubt
|
|
|