Can you compare two strings using the "==" operator?
Utilisateur anonyme
Yes, but only if they are in the string pool. For example: String a = "mama"; String b = "mama"; a == b would return true. However if you have String a = "mama"; String b = new String("mama"); //This will tell the JVM that you don't want to add the literal in the string pool and you want it to allocate a different space in the memory for your new string. therefore they could only be compared using .equals() method. Using "==" operator is NEVER advised.