0

In my following code, I convert a string array to a char array to alter the characters.

char[][] currentGuessArray = new char[currentGuessPhrase.length][];
for (int x = 0; x < currentGuessPhrase.length; x++) {
    currentGuessArray[x] = currentGuessPhrase[x].toCharArray();
}
for (int x = 0; x < correctPhrase.length; x++) {
    for (int a = 0; a < correctPhrase[x].length(); x++) {
        if (correctPhrase[x].charAt(a) == guess) {
            currentGuessArray[x][a] = guess;
        }
}

I tried the following:

for (int x = 0; x < currentGuessArray[x].length; x++){
    currentGuessPhrase[x] = currentGuessArray[x].toString();
}

But it doesn't seem to alter the code.

The string array contains random words like: "fire", "golden", "illegal", etc.

Edit: Here is an example run:

miracles
horrible
illegal
horrible
good

Those are the Strings stored in currentPhrase[]

Input: a

Expected output:

___a____ ________ _____a_ ________ ____

Actual output:

[C@5265a77f [C@fd7ad1c [C@18a61164 [C@3ebfc8e0 ____
Modify You
  • 153
  • 4
  • 14
  • why are you using a 2d array for currentGuessArray? Are you getting errors? Show your expected and actual results. – Sionnach733 Nov 20 '13 at 23:06
  • Please read **[Convert Character Array To String In Java](https://www.tutorialcup.com/java/convert-char-array-to-string-in-java.htm)** this will help you answer your question – Rahul Gupta May 14 '21 at 17:31

1 Answers1

1

simply change

currentGuessPhrase[x] = currentGuessArray[x].toString();

to

currentGuessPhrase[x] = new String(currentGuessArray[x]);
kiruwka
  • 9,250
  • 4
  • 30
  • 41