1. 把Strings转换成int和把int转换成String
[java] view plaincopy
String a = String.valueOf(2);//integer to numeric string
int i = Integer.parseInt(a);//numeric string to an int
3.获取Java现在正调用的方法名
[c-sharp] view plaincopy
String methodName = Thread.currentThread().getStackTrace()[1]
.getMethodName();
4.在Java中将String型转换成Date型
[c-sharp] view plaincopy
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date date = format.parse("2011-05-19 16:19:19");
} catch (ParseException e) {
e.printStackTrace();
}
5正则表达式验证邮箱:
String emailPatten = "[a-zA-Z0-9]+[a-z,A-Z,0-9,\\.,\\_\\-]+@[a-z,A-Z,0-9,\\-,\\_]+\\.[a-z,A-Z,0-9,\\-,\\_]+[\\.]?[a-z,A-Z,0-9,\\-,\\_]*[\\.]?[a-z,A-Z,0-9,\\-,\\_]*";
Pattern emailP = Pattern.compile(emailPatten);
Matcher emailM = emailP.matcher(email);
if(!emailM.matches()){
return "email_error_002";
}
6正则表达式验证密码:
String passwordPatten = "[\\dA-Za-z\\(!@#\\$%\\^\\&\\*\\-\\_\\)]{4,16}";
Pattern passwordP = Pattern.compile(passwordPatten);
Matcher passwordM = passwordP.matcher(password);
7map类型的遍历方法之一
Set set = map.entrySet();
Iterator it = set.iterator();
while(it.hasNext()){
Map.Entry ent = (Map.Entry) it.next();
j.put(ent.getKey()+"", ent.getValue());
}
8<s:property value='CRADCENTER_BATCH_NAME'/>===<s:property value='#cardCenterBatch.CRADCENTER_BATCH_NAME'/>!=<s:property value='cardCenterBatch.CRADCENTER_BATCH_NAME'/>
9 public static boolean isBlank(String str) 判断某字符串是否为空或长度为0或由空白符(whitespace) 构成
StringUtils.isBlank(" ") = true 而" ".equals("")为false
StringUtils.isEmpty(null) = true
StringUtils.isEmpty("") = true
StringUtils.isEmpty(" ") = false //注意在 StringUtils 中空格作非空处理
10,字符串转换为字数串集合:
String newString = channelIDs.replace(" ", "");
String [] channels =newString.split(",");
//List<String> checkedCardTypes = Arrays.asList(paycards);//该方法转换来的list不可以删除添加元素http://blog.csdn.net/thunderous/article/details/3693362
List<String> checkedChannels = new ArrayList<String>(Arrays.asList(channels));