相关疑难解决方法(0)

字符串连接:concat()vs"+"运算符

假设字符串a和b:

a += b
a = a.concat(b)
Run Code Online (Sandbox Code Playgroud)

引擎盖下,它们是一样的吗?

这里以concat反编译为参考.我希望能够反编译+运算符以查看它的作用.

public String concat(String s) {

    int i = s.length();
    if (i == 0) {
        return this;
    }
    else {
        char ac[] = new char[count + i];
        getChars(0, count, ac, 0);
        s.getChars(0, i, ac, count);
        return new String(0, count + i, ac);
    }
}
Run Code Online (Sandbox Code Playgroud)

java string concatenation

476
推荐指数
8
解决办法
91万
查看次数

算术添加和字符串连接之间的Java'+'运算符?

我们知道
Java'+'运算符用于两者

  • 算术添加
  • 字符串连接

当我一起使用时,需要知道确切预期的行为和应用规则
当我尝试遵循java代码

System.out.println("3" + 3 + 3);    // print 333    String concatenation ONLY
System.out.println(3 + "3" + 3);    // print 333    String concatenation OLNY
System.out.println(3 + 3 + "3");    // print 63     Arithmetic Add & String concatenation
Run Code Online (Sandbox Code Playgroud)

java string concatenation add

12
推荐指数
2
解决办法
3800
查看次数

标签 统计

concatenation ×2

java ×2

string ×2

add ×1