Android Object to String Convert getStringValue(Object str, String def)

Here you can find the source of getStringValue(Object str, String def)

Description

get String Value

Declaration

public static String getStringValue(Object str, String def) 

Method Source Code

//package com.java2s;

public class Main {
    public static String getStringValue(Object str, String def) {
        String s = (String) str;
        if (null == s || isEmpty(s) || "false".equals(s)) {
            s = def;//from  w  ww .j  a va 2  s  .  c  o  m
        }
        return s;
    }

    public static boolean isEmpty(String input) {
        if (input == null || "".equals(input) || "null".equals(input))
            return true;

        for (int i = 0; i < input.length(); i++) {
            char c = input.charAt(i);
            if (c != ' ' && c != '\t' && c != '\r' && c != '\n') {
                return false;
            }
        }
        return true;
    }
}

Related

  1. objToStrNotNull(Object obj)