Split string in java giving some issues -
this question has answer here:
- how compare strings in java? 23 answers
public class llearning1 { public static void main(string[] args) { string text = "is"; string x = "what good"; string y[] = x.split(" "); (string temp: y) { if (temp == text) { system.out.println("found"); } else { system.out.println("nothing"); } } } }
output:
expected : code should display "found"
but displaying "nothing"
compare string equals()
method not ==
operator
==
operator used compares reference of object.
change if (temp == text)
if (temp.equals(text))
Comments
Post a Comment