Append a single character to a string or char array in java?

前端 未结 7 1065
轻奢々
轻奢々 2020-12-13 17:31

Is it possible to append a single character to the end of array or string in java

for example:

    private static void /*methodName*/ () {                


        
7条回答
  •  庸人自扰
    2020-12-13 17:46

    new StringBuilder().append(str.charAt(0))
                       .append(str.charAt(10))
                       .append(str.charAt(20))
                       .append(str.charAt(30))
                       .toString();
    

    This way you can get the new string with whatever characters you want.

提交回复
热议问题