目录
将List<String> 类型的数组转换成用 , 隔开的字符串
public static String listConvertStr(List<String> listStr) {
StringBuffer sb = new StringBuffer();
for (String item : listStr) {
sb.append(item).append(",");
}
return sb.toString();
}
将用 , 隔开的字符串 转换成 List<String> 类型的数组
public static List<String> strConvertList(String str) {
List<String> list = new ArrayList<String>();
if (!ValidationUtil.StrisNull(str)) {
String[] strArr = str.split(",");
for (String string : strArr) {
if (!ValidationUtil.StrisNull(string)) {
list.add(string);
}
}
}
return list;
}
获取文件后缀名
public static String getSuffixName(String fileName) {
if (null != fileName && !"".equals(fileName)) {
if (fileName.lastIndexOf(".") > 0) {
return fileName.substring(fileName.lastIndexOf("."), fileName.length());
}
}
return "";
}
不够位数的在前面补0,保留num的长度位数字
private static String autoGenericCode(String code, int num) {
String result = "";
// 保留num的位数
// 0 代表前面补充0
// num 代表长度为4
// d 代表参数为正数型
result = String.format("%0" + num + "d", Integer.parseInt(code) + 1);
return result;
}
从身份证提取性别
public static String getSexByIdCard(String idCard) {
String idCardNumber = idCard.trim();
int idCardLength = idCardNumber.length();
String sex = "9";
if (idCardNumber == null || "".equals(idCardNumber)) {
return "9";
}
if (idCardLength == 18) {
if (Integer.parseInt(idCardNumber.substring(16, 17)) % 2 == 0) {
sex = "2";
} else {
sex = "1";
}
}
if (idCardLength == 15) {
if (Integer.parseInt(idCardNumber.substring(13, 14)) % 2 == 0) {
sex = "2";
} else {
sex = "1";
}
}
return sex;
}
从身份证提取出生日期 yyyy-mm-dd
public static String getBirthByIdCard(String idCard) {
String idCardNumber = idCard.trim();
int idCardLength = idCardNumber.length();
String birthday = "";
if (idCardNumber == null || "".equals(idCardNumber)) {
return birthday;
}
if (idCardLength == 18) {
String yyyy = idCardNumber.substring(6, 10);
String MM = idCardNumber.substring(10, 12);
String dd = idCardNumber.substring(12, 14);
birthday = yyyy + "-" + MM + "-" + dd;
}
return birthday;
}
获取6位随机验证码
public static String getValidationCode6() {
return String.valueOf((new Random().nextInt(899999) + 100000));
}
将句点、下划线划分的字符串转换成为驼峰形式
public static String transToFirstLower(String str){
if(str==null){
return str;
}
String[] strs = str.split("[\\.|_]");
StringBuilder sb = new StringBuilder();
for(int i=0;i<strs.length;i++){
String s = strs[i];
if(isNotBlank(s)) {
if(i==0){
sb.append(s.substring(0, 1).toLowerCase()).append(s.substring(1));
}else{
sb.append(s.substring(0, 1).toUpperCase()).append(s.substring(1));
}
}
}
return sb.toString();
}
将句点、下划线划分的字符串转换成驼峰形式,并将首字母大写
public static String transToFirstUpper(String str){
if(str==null){
return str;
}
String[] strs = str.split("\\.|_");
StringBuilder sb = new StringBuilder();
for(String s:strs){
if(isNotBlank(s)){
sb.append(s.substring(0,1).toUpperCase()).append(s.substring(1));
}
}
return sb.toString();
}