【发布时间】:2025-12-29 21:00:06
【问题描述】:
如何创建访问方法来将字符串转换为布尔值? 下面是目前的访问方式
protected boolean fullTime;
/**
* Get the value of fullTime
*
* @return the value of fullTime
*/
public boolean isFullTime() {
return fullTime;
}
/**
* Set the value of fullTime
*
* @param fullTime new value of fullTime
*/
public void setFullTime(boolean fullTime) {
this.fullTime = fullTime;
}
可以像下面这样做吗
/**
* set the coaches names
* @param coaches as an array of strings
*/
public void setCoaches(String coaches)
{
this.coaches = getStringAsArray(coaches);
}
public String getCoachesAsString()
{
return getArrayAsString(coaches);
}
【问题讨论】:
-
return new Boolean(fullTime).toString();和 Boolean.parseBoolean(yourString);
-
@RichKid 有用吗?
-
感谢您的回复,效果很好。我只需要最后一次调整。如果为真,我希望输出显示全职,如果为假,则显示兼职。到目前为止我有这个.. assert Boolean.parseBoolean("no") == false; assert Boolean.parseBoolean("yes") == true;
-
^^ @DavidPérezCabrera
-
@RichKid 已编辑调整。
标签: java arrays string methods boolean