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

前端 未结 7 1066
轻奢々
轻奢々 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:54

    First of all you use here two strings: "" marks a string it may be ""-empty "s"- string of lenght 1 or "aaa" string of lenght 3, while '' marks chars . In order to be able to do String str = "a" + "aaa" + 'a' you must use method Character.toString(char c) as @Thomas Keene said so an example would be String str = "a" + "aaa" + Character.toString('a')

提交回复
热议问题