Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-16-2007, 05:16 PM
Senior Member
 
Join Date: Nov 2007
Posts: 115
ravian is on a distinguished road
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
Sponsored Links
  #2 (permalink)  
Old 11-16-2007, 06:30 PM
ShoeNinja's Avatar
Senior Member
 
Join Date: Oct 2007
Posts: 123
ShoeNinja is on a distinguished road
Send a message via AIM to ShoeNinja
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, 08:19 PM
Senior Member
 
Join Date: Nov 2007
Posts: 115
ravian is on a distinguished road
Thanks ShoeNinja for your opinion. I now have got the right idea.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


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

vB 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
Converting an Array to a Vector Java Tip java.lang 0 04-14-2008 10:44 PM
Vector help king_arthur New To Java 3 01-22-2008 09:33 PM
array vs Vector paty New To Java 1 08-02-2007 09:07 PM
How i add string array in vector susan New To Java 1 07-16-2007 07:44 AM
Convert a vector to a string array orchid New To Java 2 05-06-2007 09:14 AM


All times are GMT +3. The time now is 09:35 PM.


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