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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:29:30+00:00 2026-06-09T20:29:30+00:00

I have a problem where the data I enter is writing to all elements

  • 0

I have a problem where the data I enter is writing to all elements in a List instead of one and I’m really struggling to figure out why, thanks for the help anyone who can..

public class Courts implements Serializable {

private static final long serialVersionUID = 1;
List<String[][]> allCourts = new ArrayList<String[][]>(10);

}

And here is the method I’m using to alter this List

public String bookCourt(int courtNo,int day,int time) throws RemoteException{
    String [][] tmp = court.allCourts.get(courtNo - 1);

    if(tmp[day-1][time-1].equals("Available")){

        tmp[day-1][time-1] = logged.name;

        court.allCourts.set(courtNo - 1,tmp);
        return "Your booking has been accepted, booking is on (" + court.courtNames[courtNo - 1] + 
                                                               "),(" + court.days[day - 1] + ") at ("
                                                               + court.times[time - 1]  + ").\n";
    }

    return "Court already taken by " + tmp[day-1][time-1] + ".\n";
}

Format came out a bit wonky there, sorry about that..

What I think this should do is get the 2D array from the allCourts list at courtNo-1 index, check if the String at the specified position is “Available” and if it is set it to logged.name.

Then it should take this updated 2D array and overwrite the array in the List with it, only problem is that it writes the name or array to every element in the allCourts List and I do not know why, again I appreciate any help yous can provide me.

  • 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-09T20:29:31+00:00Added an answer on June 9, 2026 at 8:29 pm

    I’m not sure why it is doing the specific behavior you mentioned, since to me, it looks like it should just be throwing NullPointerExceptions due to lack of initialization. I’m guessing that somewhere, you’re initializing allCourts so that all elements are the same array.

    However, some things to keep in mind. In Java, arrays are just an object like anything else. tmp is a reference to the array object which is also referenced by the reference stored at position courtNo-1 in allCourts. Calling set does not overwrite the array, it overwrites the array reference, which is already equal to tmp. So the court.allCourts.set(courtNo - 1,tmp); does nothing.

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

Sidebar

Related Questions

I have a problem with my address data. So either you enter a new
I have problem while loading data into html select when users press or click
I have a problem with Data.Serialize. When I encode a data structure then I
I have a problem returning data back to the function I want it returned
I have a problem POSTing data via HTTPS in Java. The server response is
I have a problem with data in UITableView. I have UIViewController, that contains UITableView
Android 2.1 update 1 Eclipse 3.5 I have a problem reading data from my
i have problem to correctly bind data to WPF Chart. When i'm setting ItemsSource
i have an problem with handling data come from server , please see the
I have problem SIMILAR to preventing form data reposting, but not quite the same

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.