java.lang.Boolean.valueOf()方法用法实例教程- 返回一个Boolean实例指定的布尔值。如果指定的布尔值是true,这的方法返回Boolean.TRUE;如果是假的,这个方法返回Boolean.FALSE。
width="728" height="90" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" allowfullscreen="true" id="aswift_0" name="aswift_0" style="box-sizing: border-box; left: 0px; position: absolute; top: 0px;">
id="cproIframe_u1064372_1" width="728" height="90" src="http://pos.baidu.com/acom?adn=3&at=38&aurl=&cad=1&ccd=24&cec=UTF-8&cfv=0&ch=0&col=zh-CN&conOP=0&cpa=1&dai=1&dis=0<r=https%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DHBcRyBVfSl1anmxYLk8UK62KOjnOz1sxtqMV9-KnTlr8OzYCRzDqT-tr9HBxen2-V7K6nrMecQeqU_JocevKzq%26wd%3D%26eqid%3Ddc37668e000eece500000005567b4df5<u=http%3A%2F%2Fwww.yiibai.com%2Fjavalang%2Fboolean_valueof.html&lunum=6&n=90029059_cpr&pcs=1117x587&pis=10000x10000&ps=324x315&psr=1366x768&pss=1117x1462&qn=2b50cc3472b1588e&rad=&rsi0=728&rsi1=90&rsi5=4&rss0=%23FFFFFF&rss1=%23FFFFFF&rss2=%230000FF&rss3=%23444444&rss4=%23008000&rss5=&rss6=%23e10900&rss7=&scale=&skin=&td_id=1064372&tn=text_default_728_90&tpr=1450921563725&ts=1&version=2.0&xuanting=0&exps=110212&dtm=BAIDU_DUP2_SETJSONADSLOT&dc=2&di=u1064372&ti=Java.lang.Boolean.valueOf()%E6%96%B9%E6%B3%95&tt=1450921563713.13.431.438&feid=110212" align="center,center" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" allowtransparency="true" style="box-sizing: border-box;">
描述
java.lang.Boolean.valueOf(boolean b) 返回一个Boolean实例指定的布尔值。如果指定的布尔值是true,这的方法返回Boolean.TRUE;如果是假的,这个方法返回Boolean.FALSE。
如果一个新的Boolean实例不是必需的,一般应使用此方法,优先给构造函数Boolean(boolean),因为此方法可能会产生显着提高空间和时间性能。
声明
以下是声明java.lang.Boolean.valueOf()方法
public static Boolean valueOf(boolean b)
参数
-
b - a boolean value
返回值
此方法返回一个Boolean实例,表示b。
异常
-
NA
实例
下面的例子说明了如何使用lang.Boolean.valueOf()方法。
package com.tutorialspoint; import java.lang.*; public class BooleanDemo { public static void main(String[] args) { // create 2 Boolean objects b1, b2 Boolean b1, b2; // create 2 boolean primitives and assign values boolean bool1 = true; boolean bool2 = false; /** * static method is called using class name * assign result of valueOf method on bool1, bool2 to b1, b2 */ b1 = Boolean.valueOf(bool1); b2 = Boolean.valueOf(bool2); String str1 = "Boolean instance of primitive " + bool1 + " is " + b1; String str2 = "Boolean instance of primitive " + bool2 + " is " + b2; // print b1, b2 values System.out.println( str1 ); System.out.println( str2 ); } }
让我们来编译和运行上面的程序,这将产生以下结果:
Boolean instance of primitive true is true Boolean instance of primitive false is false