• Post Reply Bookmark Topic Watch Topic
  • New Topic

I have doubt with for each  RSS feed

 
mallikarjun dontamsetti
Ranch Hand
Posts: 246
Firefox Browser Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


1.if i don't give any {} in the array it fail compilation due to initializtion
2.when i give it how it is initialized and can array store "null" value ?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The size of an array is set when it's created, and cannot be changed later. When you say int[] a = {}; you are creating an array of length zero.

On the other hand, if you say int[]a = new int[5]; you are creating an array of length five. However, you have not provided any int values for the array's elements, so each of these will initialize to zero.

An array in Java can hold primitive values or object references. If the array is declared to hold references, then it can hold null references. For example, if you say Object[] a = new Object[5]; you are creating an array of length five. In this case, each of the array's elements will initialize to null.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!