• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Initialization of arrays

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai All,
Please have a look at the following code.

class Test {
public static void main(String[] args) throws Throwable {
int ia[][] = { { 1 , 2}, null };//line1
int ja[][] = (int[][])ia.clone();
System.out.print((ia == ja) + " ");
System.out.println(ia[0] == ja[0] && ia[1] == ja[1]);
}
}
Can we assign a null value to the array of int type.

Thanks
sudha
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think so.
I think null is only to be used for object, not a numeric.
Hope this helps, if not, wait for a ranch hand to answer.
TB
 
Ranch Hand
Posts: 412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by sudha siva:
Hai All,
Please have a look at the following code.

class Test {
public static void main(String[] args) throws Throwable {
int ia[][] = { { 1 , 2}, null };//line1
int ja[][] = (int[][])ia.clone();
System.out.print((ia == ja) + " ");
System.out.println(ia[0] == ja[0] && ia[1] == ja[1]);
}
}
Can we assign a null value to the array of int type.

Thanks
sudha


Yes. Since all arrays are also objects, you can initialize an array with a null reference.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sudha,
The code is declaring and initialzing an array of array. So, each of the first arrays' elements will hold reference to the inner (second dimensional) array. And that's where null is pointing to.
HTH
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Array is inherited from the Object class. So we can have the null value.
-SR

Originally posted by Uday Kumar:
Sudha,
The code is declaring and initialzing an array of array. So, each of the first arrays' elements will hold reference to the inner (second dimensional) array. And that's where null is pointing to.
HTH

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This being a 2-dimensional array it means that the 2 row remains unconstructed!!
as the reference to the 2 row is null.
swapna
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic