java用char输出字符串_java输出char+string出现的问题

ce7976b16f0f4c28146cb93744c625cc.png

java的System.out.println();

System.out.println(ch)调用的是System.out.println(char[])这个方法

System.out.println(“ch”+ch)调用的是System.out.println(String)这个方法

/**

* Prints an array of characters and then terminate the line. This method

* behaves as though it invokes {@link #print(char[])} and

* then {@link #println()}.

*

* @param x an array of chars to print.

*/

public void println(char x[]) {

synchronized (this) {

print(x);

newLine();

}

}

/**

* Prints a String and then terminate the line. This method behaves as

* though it invokes {@link #print(String)} and then

* {@link #println()}.

*

* @param x The String to be printed.

*/

public void println(String x) {

synchronized (this) {

print(x);

newLine();

}

}

然后加号相当于string的append()

字符串的拼接看源码是使用了StringBuilder的append(Object obj) 方法

5fdb184ec538337b540d938a2107632b.png

而对于String.valueOf调用到了char数组的toString方法

39f1be58bcc37fa9bbe1675d3f2caa77.png

对char[]使用tostring

44bf80d05c71f18dfd67007f872aea2c.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值