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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:14:59+00:00 2026-06-15T09:14:59+00:00

I know pointers don’t exist the way they do in C, but I was

  • 0

I know pointers don’t exist the way they do in C, but I was wondering if something like this would be possible:

I have 5 global variables, r1 r2 r3 r4 r5, each initially initialized to null

I want to (1) find the variable that hasn’t already been used, (2) assign something to it, and then (3) manipulate that variable later in the program. However, I don’t know the status of the variables until code execution. To make up for this, I now have a bunch of if-else statements:

if(r1==null)
    r1 = [something]    
else if(r2==null)
    r2 = [something]
else if(r3==null)
    r3 = [something]
else if(r4==null)
    r4 = [something]
else if(r5==null)
    r5 = [something]

So far so good. But the problem is, I want to take the variable that was modified in the above code and use/modify that variable later in the program.

So say if r1 and r2 were NOT null, and r3 was null, r3 = [something]. I want to modify r3 later on in the program. In C/C++, I’m thinking I could have set up a pointer to r3 in the if-else statement. Then I could just modify r3 through that pointer later in the program.

Is this possible in Java? Thanks!

EDIT: forgot to mention, r1-r5 are Strings.

  • 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-15T09:15:00+00:00Added an answer on June 15, 2026 at 9:15 am

    For something this simple, you could use an array.
    You can keep an array index as pointer to the variable you want.

    String[] r = new String[5]; // all nulls
    

    and so:

    private int findFirstNull(String[] array) {
      for(int i=0; i<r.length; i++)
        if(r[i] == null)
          return i;
      return -1;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know how to work with pointers. But I don't know how do this:
I don't know my exact numbers but i'll try my best. I have a
Yes I know Ruby doesn't have pointers, but that's the closest I could get
I don't like questions with debug sessions and memory pointers pasted, but I am
I have what I think is an incredible idea, but I don't really know
I have pointers in main for which I don't know it's size. A function
(Don't know if this is strictly on-topic, but I don't see any better Stack
I would like to know how to recursively print a File[]. I have made
I don't know how to explain this very well, but here's a shot at
I'm new to rails and don't even know if this is the correct way

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.