Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-16-2007, 03:16 PM
Senior Member
 
Join Date: Nov 2007
Posts: 115
Rep Power: 0
ravian is on a distinguished road
Default Array or Vector
I have to store 10 Strings. I can do that in Array or in Vector.

Code:
Vector <String> myValues = new Vector<String>(); 
String [] myValues1 = new String[10];
Just want to know, which one is the better choice. I am talking about memory and performance issues.

Cheers
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 11-16-2007, 04:30 PM
ShoeNinja's Avatar
Senior Member
 
Join Date: Oct 2007
Posts: 123
Rep Power: 0
ShoeNinja is on a distinguished road
Send a message via AIM to ShoeNinja
Default
If you know how many items you need to store, I think an array is the way to go. The advantage of a vector is its ability to change size. Basically if a vector is full and you add another object, the memory for that object is dynamically allocated. This does not happen in an array. To increase the size of an array, you have to create a new one and copy all of the original values.

So, in my opinion, if there is no chance that you will need more than 10 Strings, go with the array.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-18-2007, 06:19 PM
Senior Member
 
Join Date: Nov 2007
Posts: 115
Rep Power: 0
ravian is on a distinguished road
Default
Thanks ShoeNinja for your opinion. I now have got the right idea.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How i add string array in vector susan New To Java 7 02-12-2009 01:32 PM
Converting an Array to a Vector Java Tip java.lang 0 04-14-2008 08:44 PM
Vector help king_arthur New To Java 3 01-22-2008 07:33 PM
array vs Vector paty New To Java 1 08-02-2007 07:07 PM
Convert a vector to a string array orchid New To Java 2 05-06-2007 07:14 AM


All times are GMT +2. The time now is 04:17 AM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org