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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:20:36+00:00 2026-06-01T23:20:36+00:00

Lets say this is the C++ code: void change(int& x){ x++; } or void

  • 0

Lets say this is the C++ code:

void change(int& x){
    x++;
}

or

void change2(int* a){
    *a++;
}

Both will change the global x, right?

So how can I do something like that in java?
Specifically, I want to point to a Vector object

But since Java has no pointers, I’m not sure what to do.
From searching the internet I saw people saying that Java does that in some other way, but I haven’t found any real example.

Thanks for
help!

  • 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-01T23:20:38+00:00Added an answer on June 1, 2026 at 11:20 pm

    In Java, instead of pointers you have references to objects. You cannot pass a primitive type by reference, but you can wrap a primitive type inside an object and then pass a reference to that object.

    Java provides the type Integer which wraps int, however this type is immutable so you cannot change its value after construction. You could however use MutableInt from Apache Commons:

    void change(MutableInt x) {
        x.increment();
    }
    

    The change to x will be visible to the caller.


    Specifically, I want to point to a Vector object

    When you write Vector v = ...; you are assigning a reference to a vector to the variable v. A reference in Java is very similar to a pointer. References are in fact implemented internally using pointers.

    Java uses pass by value. When you pass a vector to a method, you are actually copying a reference to that vector. It does not clone the vector itself. So passing a reference in Java is very similar to passing a pointer in C++.

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

Sidebar

Related Questions

Lets say I have this code: public void MyMethod(string Data, List<string> InputData) { //I
Lets say we have these 2 sample code : public synchronized void getSomething(){ this.hello
Lets say I have this code: <?php class hello { var $greeting = hello;
Lets say we have this code: bool KeepGoing = true; DataInThread = new Thread(new
Possible Duplicate: How Do I Access This Variable? Lets say I have the code:
Let's say that I have a code like this: NSAutoreleasePool* pool=[[NSAutoreleasePool alloc]init]; for(unsigned int
Lets say I have the following code. double *return_array(void) { double foo[2]; foo[0] =
Let's say I have this code: class Score { public Update(int score) { update
Lets say I have this code: <div class=user> <img class=profilepic src=someimage.jps> <div class=cleaner></div> [
Let's say I'm doing a code. This code uses kontextua ads <div class=pread> <div

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.