Say I have this String
expression
String hi = "Tom" + "Brady" + "Goat"
I know that the String pool "allows a runtime to save memory by preserving immutable strings in a pool" String Pool
How many strings will be created in the string pool?
My initial guess was 5 - "Tom"
, "Brady"
, "Goat"
, "TomBrady"
,"TomBradyGoat"
, because of the order of operations of String
concatenation (left to right?) or is it only the final result, "TomBradyGoat", that is stored in the String pool?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…