Monday 15 February 2010

java - When are two Strings interned? -


I have to compare two strings with parallel with the .equals () method. Tried sign (==) . But sometimes, both give the same answer. How do I solve it?

There are basically two things to know about inordered strings:

    < Li> Interns loaded with strings are given interns.
  • When you call the method, the strings are closed.

    Although there are some good points:

    • Integration of constant string in compile time is also a compile time constant, for example "foo" + The result of "bar" is the constant string "forum" .
    • intern () method intern is a copy , which does not return the original string in the "interned string pool" it returns.
    • Internal string garbage can not be collected. If you do not really do the intern stalls that you do, then you are leaking memory.

No comments:

Post a Comment