String comparison and String interning in Java -


when should 1 compare strings objects , when should 1 use equals method? make sure, use equals, doesn't seem efficient. in situations can string1 == string2 safe use?

thanks!

you should always use equals. can string1 == string2 work if:

  • you've made sure you've got distinct values in other way (e.g. you're using string values fetched set, comparing them other reason)
  • you know you're dealing compile-time string constants
  • you've manually interned strings yourself

it doesn't happen often, in experience.


Comments

Popular posts from this blog

silverlight - Applying a style to ItemContainerStyle in C# -

c# - NullReferenceException in MySqlClient.NativeDriver -

php - Updating recent updates - Problem in procedure - Any other approach? -