posts - 4,comments - 1,trackbacks - 0
boolean b=new Boolean(s).booleanValue(); int i=Integer.parseInt(s); long l=Long.parseLong(s); double d=Double.parseDouble(s);
posted on 2006-03-25 16:29 我的JAVA世界 阅读(538) 评论(1)  编辑  收藏

FeedBack:
# re: JAVA中将字符串s转换到其他的基本类型
2006-04-04 20:13 | 闲来观云
其实new Boolean(s).booleanValue()和Boolean.parseBool(s)是一个效果。。下面是Boolean类的部分代码。。。

/*
* @(#)Boolean.java 1.51 04/05/11
*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/

package java.lang;

public final class Boolean implements java.io.Serializable,
Comparable<Boolean>
{

private final boolean value;

public Boolean(boolean value) {
this.value = value;
}

public Boolean(String s) {
this(toBoolean(s));
}

public boolean booleanValue() {
return value;
}

public static boolean parseBoolean(String s) {
return toBoolean(s);
}

private static boolean toBoolean(String name) {
return ((name != null) && name.equalsIgnoreCase("true"));
}
  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: