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

  • Home
  • SEARCH
  • 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 6548655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:59:47+00:00 2026-05-25T11:59:47+00:00

If you add elements to an array list, one by one, for example: ArrayList

  • 0

If you add elements to an array list, one by one, for example:

 ArrayList alist = new ArrayList();
 alist.add("A");
 alist.add("B");
 alist.add("C");
 alist.add("D");

And then retrieve, say the third element by say, alist.get(2), am I guaranteed to retrieve the third element I added?

Second part of the question, assuming the answer to the first question is yes: When would I use an ArrayList versus a Vector and vice versa.

  • 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-05-25T11:59:47+00:00Added an answer on May 25, 2026 at 11:59 am

    “Guaranteed”? That’s hard to answer, because of the answer to the second part of the question.

    ArrayList is not synchronized by default; Vector is.

    So if you’re running a multi-threaded app, your ArrayList is shared, writable state, and you haven’t synchronized properly you might find that guarantee isn’t so solid.

    If you’re running in a single thread, the code you wrote would return “C”.

    You should still prefer ArrayList, because synchronization is expensive and you might not always want to pay the price.

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

Sidebar

Related Questions

I use outputPanel.setLayout(new BoxLayout(outputPanel, BoxLayout.Y_AXIS)); and then I add elements (for example JLabels, JButtons)
private List<String> longStr = new java.util.ArrayList<String>(); private List aList = null; private String []
I've created accordion like this: layout:'accordion', layoutConfig:{ animate:true } then i add elements by
When you want to add whitespace between HTML elements (using CSS), to which element
Suppose I have the following arrays: List<int[]> numbers = new List<int[]>(); numbers.Add(new int[] {
I have a Zend_Form with file element like this: ->addElement('file', 'image', array( 'required' =>
HI.. i want to add elements dynamically to listview in QT for symbian OS,
Trying to make a make generic select control that I can dynamically add elements
I have a GridView that I need to dynamically add TemplateField elements to. My
It is possible to add and remove elements from an enum in Java at

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.