People, you forget that the process of placing literal strings in a pool is called "interning." The String class has an intern () method. This method places any row in the pool, even if it is not in the pool initially (not literally). This means that the code is:
String a = "hello"; String b = new String("hello"); b = b.intern(); System.out.println(a == b);
prints " true ". Now why does anyone need this? As you can imagine, comparing a.equals(b) strings can take a long time if the strings are the same length but close to the end. (Look at the source code for .equals ().).
However, link comparison directly matches integer matching (pointers in C say), which is close to the moment.
So what does this give you? Speed. If you have to compare the same lines many times, the performance of your program will be very useful if you put these lines. If, however, you only compare strings once, then there will be no increase in performance since the interning process itself uses equals ().
Hope this explains it.
thank
ipolevoy Oct 27 2018-10-27 14:31
source share