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

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -