Why can I add characters to strings but not characters to characters?

前端 未结 7 771
陌清茗
陌清茗 2020-12-21 09:18

So I wanted to add a character to a string, and in some cases wanted to double that characters then add it to a string (i.e. add to it itself first). I tried this as shown b

相关标签:
7条回答
  • 2020-12-21 10:06
     String string = X + X;
    

    Here X i'ts threated as a variable

    You should use something as

    String string ="x x";
    

    Or

    String x = "something";
    String y = "else";
    

    then String string= x+y; should work just fine, this is because you are concatening with the "+" sign, you could also use

    string = string.concat(x+y); 
    

    or

    string = string.concat("something"+"else");
    
    0 讨论(0)
提交回复
热议问题