Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8598869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:15:36+00:00 2026-06-12T01:15:36+00:00

i am interested in using a String array as an element in a Vector

  • 0

i am interested in using a String array as an element in a Vector object. The array will always be of length 2. Is there a better way for this data structure? Reason for using the Vector is because of dynamic resizing, ie the number of elements vary and i would like to use the add and trimToSize methods for Vector.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:15:38+00:00Added an answer on June 12, 2026 at 1:15 am

    Use ArrayList and a custom object instead.

    public class MyStrings {
        private String string1;
        private String string2;
    
        public MyStrings(String string1, String string2) {
            this.string1 = string1;
            this.string2 = string2;
        }
    
        public String getString1() {
            return string1;
        }
    
        public String getString2() {
            return string2;
        }
    }
    

    Then to use it:

    List<MyStrings> list = new ArrayList<MyStrings>();
    list.add(new MyString("apple", "orange");
    // To iterate:
    for (MyStrings myStrings : list) {
        System.out.println(myStrings.getString1());
        System.out.println(myStrings.getString2());
    }
    

    Vector is no longer considered a good dynamic array in Java because of extra synchronization logic that’s more or less useless, so it just adds unnecessary overhead. ArrayList is the go-to dynamic array. You could also use LinkedList, which is a doubly-linked list.

    Of course, you should also use better naming conventions that describe what the values actually mean instead of the names that I used in my example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a datatype of std::vector<std::vector<T> > to store a 2D matrix/array. I
I trying out using regEx to split a String which gives me an array
I'm particularly interested in the following features: possibility of modifying the serialized array using
Is there any way of taking the data from an Excel-document and putting it
I have this data coming from a REST method using jquery's getJSON method. [Date.UTC(2010,0,0,0,0,0,0),
I'm having trouble getting Spring.Net to log, using Log4Net. I'm particulary interested in seeing
I am very interested in using CI phonegap and jquery to make mobile apps,
I am interested in using a onmouseover event to make a listbox appear and
I'm interested in using a code coverage tool for my next .NET project but
I'm interested in using the WMD editor in another project * but I'm not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.