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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:43:56+00:00 2026-06-14T08:43:56+00:00

I have String array like this one: String[][][][][] map = new String[9][13][2][1][1]; and when

  • 0

I have String array like this one:

String[][][][][] map = new String[9][13][2][1][1];

and when I’m trying update one fild, like this:

map[0][0][1][0][1]  = "true";

every fild is updating to “true”, this one:

map[0][1][1][0][1]

this one:

map[0][2][1][0][1]

why this is happening?

this is my code:

int UP          = 0;
int UP_RIGHT    = 1;
int RIGHT       = 2;
int DOWN_RIGHT  = 3;
int DOWN        = 4;
int DOWN_LEFT   = 5;
int LEFT        = 6;
int LEFT_UP     = 7;

String[][][][][] map = new String[9][13][2][1][1];

public PitchMoveHelper() {
    String[][] move = {
            {String.valueOf(UP), "false"},
            {String.valueOf(UP_RIGHT), "false"},
            {String.valueOf(RIGHT), "false"},
            {String.valueOf(DOWN_RIGHT), "false"},
            {String.valueOf(DOWN), "false"},
            {String.valueOf(DOWN_LEFT), "false"},
            {String.valueOf(LEFT), "false"},
            {String.valueOf(LEFT_UP), "false"}
        };

    String[][] used = {{"used", "false"}};

    for(int z = 0; z < 9; z++) {
        for(int x = 0; x < 13; x++) {
            map[z][x][0] = used;
            map[z][x][1] = move;
        }
    }

    //this.updateLeftBand();
    //this.updateRightBand();
    //this.updateTopBand();
    //this.updateBottomBand();

    map[0][0][1][0][1]  = "true"; 

    System.out.println(Arrays.deepToString(getPitchMap()));
}
  • 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-14T08:43:57+00:00Added an answer on June 14, 2026 at 8:43 am

    Your immediate problem is that the String array stores references, not actual strings. When you say

    map[z][x][0] = used;
    map[z][x][1] = move;
    

    There is a single instance of used being referenced by ALL elements [z][x][0] of map (and the same for move and [z][x][1]. Any change indexed by the 4th of 5th subscript is changing that single instance, affecting what is seen by all subscripts.

    To clarify more, all the following entries in map point to the same instance:

    map[0][0][0]
    map[0][1][0]
           .
           .
    map[0][12][0]
    map[1][0][0]
      etc.
    

    To solve the problem you need to make a deep copy of used and move for every assignment in the loop:

    for(int z = 0; z < 9; z++) {
        for(int x = 0; x < 13; x++) {
            map[z][x][0] = deepCopy(used);
            map[z][x][1] = deepCopy(move);
        }
    }
    

    Where deepCopy() makes a complete copy of the input array.

    String[][] deepCopy(String [][] arr)
    {
        String[][] temp = new String[arr.length][];
        for (int i=0; i<arr.length; i++)
        {
             temp[i] = new String[arr[i].length];
             for (int j=0; j<arr[i].length; j++)
                 temp[i][j] = arr[i][j];
        }
        return temp;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string array like this. string[] queries with data more than one
I have string that look like Array that fetched from other webservice like this
I have a string like this: TEST.DATA.Data.COR.Point,2;TEST.DATA.Data.COR.Point,5;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.WordTOFIND,18 I have a list of array with
How do i explode this string '||25||34||73||94||116||128' i need to have a array like
Lets say I have string like this: String q = foo (one) bla (two)
I have a string like this one: traceroute <ip-address|dns-name> [ttl <ttl>] [wait <milli-seconds>] [no-dns]
Ok so I have an array that looks like this. [Enter Sandman, One, Nothing
An array is defined of assumed elements like I have array like String[] strArray
So, I have a string array of some random saying and the like, but
I have string like {param1=foo}{param2=bar}hello world! I need to extract array of tuples (paramName,

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.