As far as I know, Strings in Java are immutable and every time we try to change a String Java creates the new String in a String pool and re-references us to this new String. It is said that if we want to change a String we should use a String Builder or a String Buffer. My question is: What really happens when we use inbuilt String methods like trim(),replaceFirst(), and others that change created String. Does Java create a new String and still re-references or we change the already created String.
I tried to Google but didn't find an appropriate answer. It may be me whose google skills are not the best :)
I hope that I've made my question clear and thanks in advance.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…