How can i compare a string and a char array in java?

前端 未结 4 1189
余生分开走
余生分开走 2021-01-17 22:56

In my program I\'m trying to compare my char array asterixA[] to string (word) in an if loop like:

if (word.equals(asterixA))

4条回答
  •  误落风尘
    2021-01-17 23:51

    you have to convert the character array into String or String to char array and then do the comparision.

    if (word.equals(new String(asterixA)))
    

    or

    if(Arrays.equals(word.toCharArray(), asterixA))
    

    BTW. if is a conditional statement not a loop

提交回复
热议问题