How to concatenate string in java
问题 Here is my code for string concatenation. StringSecret.java public class StringSecret { public static void main(String[] args) { String s = new String("abc"); s.concat("def"); System.out.println(s); } } I expected that the output will be "abcdef" but I am getting only "abc" printed. What's the problem !. 回答1: In java, string objects are immutable . Immutable simply means unmodifiable or unchangeable. Once string object is created its data or state can't be changed but a new string object is