Strings can come from many places, and by default only string literals are in the string pool. For example, when you call BufferedReader.readLine() , the returned row is not in the row pool.
Whether it makes sense to combine such strings using String.intern() or a String.intern() map depends on how much duplication you have and how much memory you can save to reduce this duplication.
For example, if you are reading an XML file, it can be very useful to canonicalize element names. If you are reading a file with address data, it may be useful to canonize zip codes and / or city names. However, in both cases, I would look at using Map , rather than calling intern() , because the latter consumes permgene memory (which is a scarce resource than regular heap memory).
source share