java的每个数据类型每次转换都需要再去翻查资料 ,为此我在这里写了一个String字符串的工具类 。希望和大家分享一下!
/**
* String去掉全部空格
*
* @param str
* 传来一个字符串
* @return 去掉空格字符串
*/
public String trim(String st){
st=st.replace(" ", "").trim();
return st;
}
/**
* 转换编码的方法
*
* @param str
* 传来一个字符串
* @return 返回一个转码后的字符串
*/
public static String getEncoding(String str) {
try {
str = new String(str.getBytes("ISO-8859-1"), "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return str;
}
/**
* 检查字符串是否为空
*
* @param str
* 要检查的字符串
* @return boolean
*/
public static boolean isNull(String str) {
if (str == null || str.length() == 0 || "".equals(str)) {
return false;
} else {
return true;
}
}