public static boolean stringToBoolean(String $str)
{
boolean result = false;
boolean isInt = false;
int intResult = 0;
try
{
intResult = Integer.parseInt($str);
isInt = true;
} catch (Exception e)
{
}
if (isInt)
{
result = intResult == 1;
}
else
{
result = Boolean.parseBoolean($str);
}
return result;
}
public static boolean intToBoolean(int $int)
{
return stringToBoolean($int + "");
}
Log.w("###", "result1 : " + stringToBoolean("0")); // false
Log.w("###", "result2 : " + stringToBoolean("1")); // true
Log.w("###", "result3 : " + stringToBoolean("-1")); // false
Log.w("###", "result4 : " + stringToBoolean("true")); // true
Log.w("###", "result5 : " + stringToBoolean("false")); // false
Log.w("###", "result6 : " + stringToBoolean("true1")); // false
Log.w("###", "result7 : " + stringToBoolean("false1")); // false;
댓글을 달아 주세요