File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array of 0 elements ..

 
Tejas Tambe
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Khalid Mughal says, in Java arrays of 0 elements can be CONSTRUCTED.
Suppose i declare an array as :
int[] arr1 = new arr[0];
This line of code compiles fine. But when executed it fires a ArrayOutOfBoundException. In such a case a question just popped up, why then allow to create an array of 0 elements. What is achieved ??
Please help me to understand this funda better,
Thanx in advance,
Tejas
 
Neha Sawant
Ranch Hand
Posts: 204
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tejas,
You can create an array of length 0
if you type arr1.length, output will show you that it is 0 length.
but if you try to type arr1[0] then it will definetely throw runtime excep. ArrayIndexOutOfBoundException as u are asking for the first element arr1[0] which it does not have since it is of length 0
hope it helps
Regards
Neha
 
Tejas Tambe
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx neha,
but the thing that's bugging me is that WHY ALLOW TO CREATE array of size 0. What is achieved ???
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now what if someone calls Application.getActiveUsers() while there are no such users at that moment?
- Peter
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic