File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array vs Vector

 
Mandy Smith
Ranch Hand
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a situation where user can input the name of the files through html form (1 or 2 file, max is 2 files).
Is it better to hold the file names in an array or in a vector?
The problem is if i store it in an array, as the size of the array is 2. The element at location 2 in the array is null, which is leading to nullpointerexception when user submits only 1 file name. So, i am using vector instead of array to avoid this exception.
Is this ok to do? If not, what's is the efficient way to do?
Appreciate your input.
Thanks,
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sure , no problem... but maybe consider using ArrayList which is better than Vector.
 
Mandy Smith
Ranch Hand
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your input!
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mandy Smith:
The problem is if i store it in an array, as the size of the array is 2. The element at location 2 in the array is null, which is leading to nullpointerexception when user submits only 1 file name. So, i am using vector instead of array to avoid this exception.

Why don't you instantiate an array of the correct size (1 or 2 depending on the number of entered file names?
Can you post some code?
 
Dean Jones
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As such u should not have any problem in using the arrays if the no. of elements are fixed. u shuld remember that array indexes starts from zero instead of 1 , so if u have used a array with the limit two say Array a[2]; and latter u trying to access a[2] element this will trey to acces the third element and thus will generate e exeption ArrayOutOfBoundsEexception,but in ur case it is null pointer esception so might be ur not able to put the data in the array b4 using it
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic