码迷,mamicode.com
首页 > 编程语言 > 详细

java API------Boolean类valueOf()方法

时间:2014-09-04 00:16:27      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:blog   io   java   2014   log   on   amp   c   line   

//摘自ocjp
public void testIfA() {
	if (testIfB("True")) {
		System.out.println("True");	
	} else {
		System.out.println("Not true");
	}
 }
public Boolean testIfB(String str) {
	return Boolean.valueOf(str);
}

What is the result when method testIfA is invoked?
A. True
B. Not true
C. An exception is thrown at runtime.
D. Compilation fails because of an error at line 12.
E. Compilation fails because of an error at line 19.
Answer: A


分析:

查看API:

//摘自Jdk1.6.21 API--Boolean类。
    public static Boolean valueOf(String s) {
	return toBoolean(s) ? TRUE : FALSE;
    }

    private static boolean toBoolean(String name) { 
	return ((name != null) && name.equalsIgnoreCase("true"));
    }

不难看出,此处不区分大小写。


java API------Boolean类valueOf()方法

标签:blog   io   java   2014   log   on   amp   c   line   

原文地址:http://blog.csdn.net/pingzizzp/article/details/39035865

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!