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 6906887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:22:01+00:00 2026-05-27T08:22:01+00:00

I have the following two Vector objects in java. Vector<SomeClass> obj1; Vector<SomeClass> obj2; The

  • 0

I have the following two Vector objects in java.

Vector<SomeClass> obj1;
Vector<SomeClass> obj2;

The class SomeClass has an int variable a.

Assume obj2 is empty and obj1 has some elements in it. Suppose I do this:

obj2.add(obj1.firstElement()); 
obj2.firstElement().a = 10;  // obj2.firstElement() will be the object that was 
                             //added above because obj2 was empty at first

Would this change the value of a in obj1.firstElement() too?

Basically I just want to know if these Vector operations are done by reference or value. My guess is that they are done by reference and this change will be reflected in obj1.firstElement() too.

  • 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-27T08:22:01+00:00Added an answer on May 27, 2026 at 8:22 am

    You are right, the reference is copied (shallow copy) and so the change is reflected also in the original vector.

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

Sidebar

Related Questions

Suppose I have the following two data structures: std::vector<int> all_items; std::set<int> bad_items; The all_items
I have the following two tables: Customer { int Id int Name } Bills
I have the following two classes, one inherits from the other Class A{ void
I have the following two classes: public class Address { public string AddressLine1 {
I have the following two programs: long startTime = System.currentTimeMillis(); for (int i =
I have a main function in A.cpp which has the following relevant two lines
I have a set of pointers to objects of the following class: class name_id
I have the following two boost::fusion maps. namespace bf = boost::fusion; typedef bf::map<bf::pair<char,float>,bf::pair<int,double>> FusionMap;
I have the following: class Parent { public: virtual bool foo(vector<string> arg1, vector<string> arg2)
I have defined two dimensional array using following definition typedef std::vector<std::vector<short> > table_t; Can

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.