File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Can new vector be null ??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Can new vector be null ???" Watch "Can new vector be null ???" New topic
Author

Can new vector be null ???

Arun Thakur
Greenhorn

Joined: Mar 15, 2006
Posts: 17
I have :

Vector vet = new Vector(10);

Can items of vet be null at this point ???
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
No the vector has no items in it. The parameter to the constructor is simply the initial capacity of the Vector, but when it's created by that constructor, it is empty.
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
Originally posted by Arun Thakur:
I have :

Vector vet = new Vector(10);

Can items of vet be null at this point ???


Depends on your definition of "items".
No, you cannot observe "items of vet to be null" through the contract of the type, however, if you were running in a debugger, you'd likely observe a field (which is of course, not exposed directly through contract) of an array type that contains null elements.


Tony Morris
Java Q&A (FAQ, Trivia)
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
Originally posted by Tony Morris:
Depends on your definition of "items".
No, you cannot observe "items of vet to be null" through the contract of the type, however, if you were running in a debugger, you'd likely observe a field (which is of course, not exposed directly through contract) of an array type that contains null elements.


Unless of course you add null elements to the Vector in which case you could. Though I presume they're asking if the new Vector will have 10 null elements in it. The answer is, of course, no. As Tony said the underlying implementation will have an array with null values, but that is irrelevent. As far as the Vector is concerned it has a size of 0 and attempting to retrieve from it will result in an exception. You'll have to actually add an element yourself. You can add null if you like, but I don't know why you would.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can new vector be null ???
 
Similar Threads
About gc
Query woes - determined but struggling
Using result sets, statements & connections
Value in dropdown from servlet
Validate if vector is null