Split string in java giving some issues -


this question has answer here:

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

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -