0
如何創建將字符串轉換爲布爾值的訪問方法?下面如何創建訪問方法來將字符串轉換爲布爾值
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);
}
回報新布爾(全日制)的ToString();和Boolean.parseBoolean(yourString); –
@RichKid有用嗎? –
感謝您的迴應,它運作良好。我只需要最後一次調整。我希望輸出顯示爲全時,如果爲真,則爲部分時間(如果爲假)。我有這個到目前爲止.. assert Boolean.parseBoolean(「no」)== false; assert Boolean.parseBoolean(「yes」)== true; –