Java Utililty Methods String Value Of

List of utility methods to do String Value Of

Description

The list of methods to do String Value Of are organized into topic(s).

Method

BooleanvalueOf(String s)
value Of
return valueOf(parseBoolean(s));
longvalueOf(String s)
value Of
long time = 0L;
for (String st : s.split(" ")) {
    if (st.endsWith("d")) {
        time += Long.valueOf(st.substring(0, st.length() - 1)) * 86400L;
        continue;
    if (st.endsWith("s")) {
        time += Long.valueOf(st.substring(0, st.length() - 1));
...
EvalueOf(String s, Class e)
value Of
try {
    return Enum.valueOf(e, s);
} catch (IllegalArgumentException ex) {
    ex.printStackTrace();
return null;
IntegervalueOf(String s, int def)
This function always returns an int.
try {
    return Integer.valueOf(s);
} catch (Exception e) {
    return def;
StringvalueOf(String str)
return "" if value is null otherwise return same string
if (str == null)
    return "";
return str;
LongvalueOf(String str)
Parse String to Long.
try {
    return Long.valueOf(str.trim());
} catch (Exception ex) {
    return null;
booleanvalueOf(String stringVal, boolean dVal)
value Of
try {
    return Boolean.valueOf(stringVal);
} catch (Exception e) {
    return dVal;
booleanvalueOf(String value)
Returns true if value equals "true", "on", "yes" or "1".
if (value == null) {
    return false;
value = value.trim().toLowerCase();
return (value.equals("true") || value.equals("on") || value.equals("yes") || value.equals("1"));
booleanvalueOf(String value)
Determines if the specified string contains 'true' or '1'
return (value != null) && (value.trim().equalsIgnoreCase("true") || value.trim().equals("1"));
booleanvalueOf(String value, boolean defaultValue)
value Of
if (value == null)
    return defaultValue;
return Boolean.valueOf(value);