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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:44:45+00:00 2026-05-30T10:44:45+00:00

I have 2 separate objects, created separately, but when i change one the other

  • 0

I have 2 separate objects, created separately, but when i change one the other once changes too.

Here is the object creation code:

private sMap unsolvedSudoku = new sMap();
private sMap solvedSudoku = new sMap();
private sMap userSudoku = new sMap();

algorithm alg = new algorithm(unsolvedSudoku);

And here is the code that changes one object:

//Generate a new sudoku
alg.generateFullList(); // - This changes unsolvedSudoku
solvedSudoku.setMatrix(unsolvedSudoku.getMatrix()); // - This basically copies an array of numbers from unsolvedSudoku to solvedSudoku.
new algorithm(solvedSudoku).printMap(); //  This just prints out the array of numbers
alg.removeRandomNumbers(level); // This removes random numbers from unsolvedSudoku
new algorithm(solvedSudoku).printMap(); // this prints out the array again.

the first printMap and the second printMap are different, but they shouldn’t be (at least to my knowledge). Why is that? Also, the sMap class doesn’t have any static variables or methods

  • 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-30T10:44:47+00:00Added an answer on May 30, 2026 at 10:44 am

    I suspect the issue is here:

    solvedSudoku.setMatrix(unsolvedSudoku.getMatrix());
    

    You’re just copying a reference to the same array instance, not actually copying its contents. To copy an array, you can use System.arraycopy(). The Arrays utility class also has some useful methods for copying arrays.

    I’m assuming from the name “matrix” that this is a 2d array – in that case it will not be as simple as just copying the outer dimension, because the elements will still be references to the same inner arrays. You will need to individually copy each inner array into a new outer array.

    I’ll leave it up to you to figure this out, since you now have the tools for it.

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

Sidebar

Related Questions

Hello I have problem to put together animations of two separate objects to second
What's the best way to have separate CSS for IE and other browsers? I'm
My app uses two databases (separate files). To handle these databases I have created
I have a fractal object that is created with random values to its variables.
I have a weird situation where I have created a separate validation class for
Here's my problem: I have a Flash object on my page. The user can
I have a list of class items List<MyClass> I have a seperate object that
In my ASP.NET application I have separate projects for the Data, Business and UI
I have web application which we deployed in a production . We have separate
I have 2 separate java services that use a complex type that is a

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.