String.valueOf 默认的方法

argument 可以为null 的

  1. boolean b = null;
  2. char c = null;
  3. char[] data = null;
  4. double d = null;
  5. float f = null;
  6. int i = null;
  7. long l = null;
  8. Object obj = null;

String.valueOf(null) 会调用更为具体valueOf(char[] data)

    /**
* Returns the string representation of the <code>char</code> array
* argument. The contents of the character array are copied; subsequent
* modification of the character array does not affect the newly
* created string.
*
* @param data a <code>char</code> array.
* @return a newly allocated string representing the same sequence of
* characters contained in the character array argument.
*/
public static String valueOf(char data[]) {
return new String(data);
} /**
* Allocates a new {@code String} so that it represents the sequence of
* characters currently contained in the character array argument. The
* contents of the character array are copied; subsequent modification of
* the character array does not affect the newly created string.
*
* @param value
* The initial value of the string
*/
public String(char value[]) {
this.value = Arrays.copyOf(value, value.length);
}

会在value.length 处抛空指针异常!

case1:

String.valueOf(null);

case2:

char[] data;

String.valueOf(data);

String.valueOf(null) 报空指针的更多相关文章

  1. Integer.valueof(null)报错

    原文  http://javacat360.iteye.com/blog/2024378 主题 Java 昨天,一同事问我一个问题,估计是他前段日子面试遇到的 问题很简单,String.valueof ...

  2. 从String.valueOf(null)说起

    同学在群问String.valueOf(null)返回啥,我看了下源码,返回"null"啊,   public static String valueOf(Object obj) ...

  3. String.valueOf(null)

    public static String valueOf(Object obj) { return (obj == null) ? "null" : obj.toString(); ...

  4. 说说JDK中的String.valueOf()传null的诡异处理

    都说JDK的实现诡异多,今儿也算是被我踩到一个坑了. 就来说说关于String.valueOf的这个坑. public class TestString { public static void ma ...

  5. 转换String三种方式比较:toString()、String.valueOf()、(String)

    简单介绍: 1.toString,需要保证调用这个方法的类.方法.变量不为null,否则会报空指针. 2.String.valueOf.这个方法在使用的时候是有些特殊的.一般情况下,如果是确定类型的n ...

  6. Java中String.valueOf、toString、(String)的区别

    原文地址http://blog.csdn.net/yangzhaomuma/article/details/51173138 原文地址https://www.cnblogs.com/xhyouyou/ ...

  7. Java中区别.toString() ,(String),valueOf()方法

    在java项目的实际开发和应用中,常常需要用到将对象转为String这一基本功能.本文将对常用的转换方法进行一个总结.常用的方法有Object.toString(),(String)要转换的对象,St ...

  8. (String)、toString、String.valueOf的区别

    String.valueOf()它可以将JAVA基本类型(int,double,boolean等)和对象(Object)转换成String型toString()是对象的方法,它可以将该对象转换成Str ...

  9. Java 之String.valueOf(obj)

    实例代码如下: String str = null; String uSelectDate = String.valueOf(str); System.out.println("====== ...

随机推荐

  1. ubuntu16.04 64位server安装php7

    You can do the following: sudo apt-get install python-software-properties sudo LC_ALL=C.UTF-8 add-ap ...

  2. Linux diff patch

    /***************************************************************************** * Linux diff patch * ...

  3. Python [Leetcode 121]Best Time to Buy and Sell Stock

    题目描述: Say you have an array for which the ith element is the price of a given stock on day i. If you ...

  4. POJ 1306 Combinations

    // 求 C[n][m] // 组合公式 C[i][j]=C[i-1][j-1]+C[i-1][j]; #include <iostream> #include <string> ...

  5. Linux/Unix shell 自动发送AWR report

    观察Oracle数据库性能,Oracle自带的awr 功能为我们提供了一个近乎完美的解决方案,通过awr特性我们可以随时从数据库提取awr报告.不过awrrpt.sql脚本执行时需要我们提供一些交互信 ...

  6. 响应式设计中几个class区别

    table-responsive:在小屏幕时不对内容做任何额外排版,只是允许左右滑动 scrollable-area:先尝试挤压起来,实在不行再左右滑动

  7. Yii与表单交互的三种模式2

    在yii的标签中加入css或js方法:echo $form->textField($model,'starttime',array(        'onclick'=>'alert(&q ...

  8. JQuery实现分页程序代码,源码下载

    Web开发,分页在所难免的,微软GridView.AspPager等设置分页数据可以自动分页,但是这里浏览器会闪动,用户体验不是很友好,在此我整理了JQuery实现分页,并且使用 JQuery模板显示 ...

  9. C++ 虚拟继承

    1.为什么要引入虚拟继承 虚拟继承是多重继承中特有的概念.虚拟基类是为解决多重继承而出现的.如:类D继承自类B1.B2,而类B1.B2都继 承自类A,因此在类D中两次出现类A中的变量和函数.为了节省内 ...

  10. switch……case不能匹配字符串的方法 .xml

    pre{ line-height:1; color:#d1653c; background-color:#000000; font-size:16px;}.sysFunc{color:#566d68; ...