如何创建将字符串转换为布尔值的访问方法

How do you create an access method to convert a string to a boolean

如何创建将字符串转换为布尔值的访问方法? 当前访问方法如下

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);
}

这是你想要的吗?

protected boolean fullTime;

public String isFullTimeAsString() {
    return String.valueOf(fullTime);
}

public void setFullTime(String fullTime) {
    this.fullTime = Boolean.parseBoolean(fullTime);
}

像这样?

protected boolean fullTime;

public String getFullTimeAsString(){
    return Boolean.toString(fullTime);
}

public void setFullTimeAsString(String fulltimeStr){
    fullTime = "true".equalsIgnoreCase(fulltimeStr);
}

已编辑:

private static final String YES = "yes";
private static final String NO = "no";
protected boolean fullTime;


public String isFullTimeAsString() {
    return fullTime? YES: NO;
}

public void setFullTime(String fullTime) {
    this.fullTime =YES.equalsIgnoreCase(fullTime);
}