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

2022-08-31 15:47:56

是否可以将单个字符附加到 java 的末尾或 java 中。例:arraystring

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?               
}

答案 1
1. String otherString = "helen" + character;

2. otherString +=  character;

答案 2

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