Search code examples
javastringcharactertostringcpu-word

using toString to form a String with Characters


using the toString method to add characters into my string I form the word "LAUGHTER". However, the program does not recognize the word = "LAUGHTER" and therefore it did not enter my if loop. Any idea why is it like that?

word += Character.toString(cList.get(i));

if(word == "LAUGHTER" )
{
    System.out.println(word);
}

Solution

  • use equals to determine string content is equivalent

    word.equals("LAUGHTER")