在java中将单个字符附加到字符串或char数组中?

Cod*_*ver 47 java string append

是否可以在java中将单个字符附加到数组或字符串的末尾

例如:

    private static void /*methodName*/ () {            
          String character = "a"
          String otherString = "helen";
          //this is where i need help, i would like to make the otherString become 
         // helena, is there a way to do this?               
      }
Run Code Online (Sandbox Code Playgroud)

And*_*ler 89

1. String otherString = "helen" + character;

2. otherString +=  character;
Run Code Online (Sandbox Code Playgroud)


小智 8

您将要使用静态方法Character.toString(char c)首先将字符转换为字符串。然后,您可以使用普通的字符串连接功能。


Ank*_*ain 6

new StringBuilder().append(str.charAt(0))
                   .append(str.charAt(10))
                   .append(str.charAt(20))
                   .append(str.charAt(30))
                   .toString();
Run Code Online (Sandbox Code Playgroud)

这样你就可以获得你想要的任何字符的新字符串.