1.字符串工具类
package com.text;
import com.text.CheckTools;
/**
*
* @author Administrator 字符串工具类
*/
public class StringTools {
// 将字符串转换成数组,按照条件condition分割
public static String[] strTransArr(String s, String condition) {
if (CheckTools.isValid(s)) {
return s.split(condition);
}
return null;
}
// 将数组变换成字符串,使用","号分割
public static String arrTransStr(Object[] obj) {
String temp = "";
if (CheckTools.isValid(obj)) {
for (Object o : obj) {
temp = temp + o + ",";
}
return temp.substring(0, temp.length() - 1);
}
return temp;
}
// 判断数组中是否含有指定字符串
public static boolean arrConStr(String[] values, String value) {
if (CheckTools.isValid(values)) {
for (String s : values) {
if (s.equals(value)) {
return true;
}
}
}
return false;
}
// 获得字符串的描述信息
public static String getStrInfo(String str) {
if (str != null && str.trim().length() > 10) {
return str.substring(0, 10);
}
return str;
}
}
2.校验工具类
package com.text;
import java.util.Collection;
@SuppressWarnings("rawtypes")
/**
*
* @author Administrator
* 校验工具类
*/
public class CheckTools {
// 判断集合的有效性
public static boolean isValid(Collection c) {
if (c == null || c.isEmpty()) {
return false;
}
return true;
}
// 判断数组是否有效
public static boolean isValid(Object[] o) {
if (o == null || o.length == 0) {
return false;
}
return true;
}
// 判断字符串有效性
public static boolean isValid(String s) {
if (s == null || "".equals(s.trim())) {
return false;
}
return true;
}
}
另:
所有的代码都是为了方便我们的工作,从繁琐复杂的循环中,变得轻松简单,有些时候觉得程序员是一个伟大的工作,是帮助的人类生活变得方便但是,如果我们只是把自己的技术知识只是放在自己的小范围内,自己的大脑中,自己的心中,自己的朋友中,其意义何在呢!,希望大家也可以花一点时间
写出你的技术,写出你工作的意义,写出一个程序员的精彩。
【welcome here :csdn communication center qq群:678470500】