功能性小代码

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));   


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值