首页 > 编程语言 > 详细

java输出char+string出现的问题

时间:2019-11-03 21:34:43      阅读:87      评论:0      收藏:0      [点我收藏+]

技术分享图片

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 <code>{@link #print(char[])}</code> and
     * then <code>{@link #println()}</code>.
     *
     * @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 <code>{@link #print(String)}</code> and then
     * <code>{@link #println()}</code>.
     *
     * @param x  The <code>String</code> to be printed.
     */
    public void println(String x) {
        synchronized (this) {
            print(x);
            newLine();
        }
    }

然后加号相当于string的append()
字符串的拼接看源码是使用了StringBuilder的append(Object obj) 方法
技术分享图片
而对于String.valueOf调用到了char数组的toString方法
技术分享图片

对char[]使用tostring
技术分享图片

java输出char+string出现的问题

原文:https://www.cnblogs.com/Emcikem/p/11788933.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!