字符串工具类(一)

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】


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值