将其他类型的变量转换成字符串有几种方法啊??
  请大家讲讲
   我知道有两种:
1.                            2.         
   int i=10;                    用toString方法                         
  String s=""+i;                              
还有什么方法啊??

解决方案 »

  1.   

    用String的构造函数和String.valueOf
      

  2.   

    如果是数组可以用New String(数组,0,位置)
      

  3.   

    所有的这些转化的前提都是在 转化的目标串都已经实现了 toString方法。
    String.valueOf() 也是
    源码如下 :
    ///////////////////////
        /**
         * Returns the string representation of the <code>Object</code> argument.
         *
         * @param   obj   an <code>Object</code>.
         * @return  if the argument is <code>null</code>, then a string equal to
         *          <code>"null"</code>; otherwise, the value of
         *          <code>obj.toString()</code> is returned.
         * @see     java.lang.Object#toString()
         */
        public static String valueOf(Object obj) {
    return (obj == null) ? "null" : obj.toString();
        }
    ///////////////////////基本类型时是 在String.valueOf 时作了转化的。
    而且其他的类,要么是自己已经实现了toString方法,要么是程序员自己实现它。
    否则你只能都看到 xxxx@xxxxx
      

  4.   

    大家都说完了。
    用char的数组算不??