码迷,mamicode.com
首页 > 其他好文 > 详细

String使用和方法

时间:2019-12-29 16:56:58      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:com   parse   定位   倒序   连接   als   位置   tar   fir   

String a = "abc";
        //返回String必须是常量池的
        String intern = a.intern();
        //长度
        int length = a.length();
        //指定位置的字符
        char charAt = a.charAt(0);
        //是否空串
        boolean empty = a.isEmpty();
        //转小写
        String s = a.toLowerCase();
        //转大写
        String s1 = a.toUpperCase();
        //收尾去空格
        String trim = a.trim();
        //比较内容
        boolean asd = a.equals("asd");
        //忽略大小写比较
        boolean b = a.equalsIgnoreCase("asd");
        //连接字符串
        String asd1 = a.concat("asd");
        //比较字符串大小
        int asd2 = a.compareTo("asd");
        //字符串截取
        String substring = a.substring(1,2);
        //判断结束
        boolean a1 = a.endsWith("a");
        //判断开始可规定开始位置
        boolean a2 = a.startsWith("a", 1);
        //是否包含
        boolean asd3 = a.contains("asd");
        //第一次出现的位置可指定开始位置
        int a3 = a.indexOf("a",1);
        //倒序第一次出现
        int a4 = a.lastIndexOf("a");
        //字符串的字符替换
        String replace = a.replace(‘a‘, ‘b‘);
        //符合正则替换
        String s2 = a.replaceAll("\\w","b");
        //同replaceAll只替换第一个
        String s3 = a.replaceFirst("a", "b");
        //是否符合正则
        boolean matches = a.matches("\\n");
        //切片(可使用正则拆分)可指定起始位置
        String[] split = a.split("\\,", 2);
        //String转包装类
        int i = Integer.parseInt(a);
        //包装类转String
        String s4 = String.valueOf(i);
        //String转char
        char[] chars = a.toCharArray();
        //String转byte[]可指定编码需处理异常
        byte[] bytes = a.getBytes("gbk");

String使用和方法

标签:com   parse   定位   倒序   连接   als   位置   tar   fir   

原文地址:https://www.cnblogs.com/aikang525/p/12115185.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!