Change instance

in main, i’m creating an object. then i’m calling a method that seems to change the object like i want. but when i call another method, it makes a change to the original object and ignores the first change.

public class Sudoku  {
   // public class Sudoku  {
    String[][] solutions = new String[9][9];
    String[][] possibilities = new String[9][9];
    String possibility = "123456789";
    boolean isSolved = false;
    int numChanges = 0;

        
    // constructor
    public Sudoku() {      
        for (int i = 0; i<9;i++) {
            for (int j=0; j<9; j++) {
                possibilities[i][j] = possibility;
            }
        }
        solutions[0][3] = "5";
        solutions[1][2] = "6";
        solutions[4][8] = "2";
        solutions[6][1] = "1";
    }
    

    public Sudoku checkRow() { 
        int numChanges = 0;
        String value = null;
        for (int i = 0; i<9;i++) {
            for (int j=0; j<9; j++) {
            if (solutions[i][j] != null) {
                
                System.out.println("solutions["+ i + "][" + j + "] " + solutions[i][j]);
                value = solutions[i][j];
                for (int a = 0; a<9; a++) { 
            possibilities[a][j].replace(value,"");
            numChanges++;
            possibilities[i][a] = possibilities[i][a].replace(value,"");
numChanges++;
    }
    }
    }
        }

return this;
    }
    
    public Sudoku checkCol() { 
        System.out.println("possibilities beginning of checkcol: " + this.possibilities[1][2]);
        int numChanges = 0;
        String value = null;
        for (int i = 0; i<9;i++) {
            for (int j=0; j<9; j++) {
            if (solutions[i][j] != null) {             
                value = solutions[i][j];
                for (int a = 0; a<9; a++) {               
            this.possibilities[a][i].replace(value,"");
            numChanges++;
            this.possibilities[j][a] = this.possibilities[i][a].replace(value,"");
numChanges++;
    }
    }
    }
        }

return this;
    }

    
    public static void main(String[] args) {
        Sudoku puzzle = new Sudoku();
        System.out.println("solution: "+ puzzle.solutions[1][2]);
        System.out.println("possibilities: "+ puzzle.possibilities[1][2]);
        puzzle = puzzle.checkRow();
        
System.out.println("possibilities after checkrow: "+ puzzle.possibilities[1][2]); // this is correct
        System.out.println("End of checkRow; back in Main");

     puzzle =  puzzle.checkCol();
        System.out.println("possibilities after checkcol: "+ puzzle.possibilities[1][2]); // this shows only new change

        System.out.println("num changes= " + numChanges);
for (int i = 0; i<9;i++) {
            for (int j=0; j<9; j++) {
            System.out.println(possibilities[i][j]);
            }
}
    }    
}

i don’t understand why it ignores the first change.

Which particular method isn’t generating the change you want?
Have you tried leaving statements to trace your code (like near the end of the return value in the method that’s not working as desired?)

i took the print statements out before posting. i’ve re-tested and it seems now to be doing what i want. i think… i will post again if something is wrong. thanks for looking!