zoukankan      html  css  js  c++  java
  • java输出char+string出现的问题

    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

  • 相关阅读:
    scrapy入门
    xpath的基本使用
    xpath 的用法
    线程同步
    Round #336 A. Saitama Destroys Hotel(Div.2)
    hdoj 1166 敌兵布阵(线段树and树状数组)
    hdoj 1873 看病要排队
    hdoj 2289 Cup
    hdoj 2689 Sort it
    hdoj 1150 Machine Schedule
  • 原文地址:https://www.cnblogs.com/Emcikem/p/11788933.html
Copyright © 2011-2022 走看看