A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

艹坏小子

初级黑马

  • 黑马币:15

  • 帖子:5

  • 精华:0

© 艹坏小子 初级黑马   /  2018-11-14 19:30  /  493 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

字符串转换
Public String replaceAll(String regex, String replacement)  内容替换
Public String replaceFirst(String regex,  String replacement)  替换首个

字符串截取
Public String substring (int beginIndex)     从指定索引开始截取全部
Public String substring(int beginIndex, int endIndex)   截取部分

字符串拆分
Public String[] split(String regex)                       按照指定字符串进行全部拆分
Public String[] split(String regex, int limit)          limit决定数组长度
*拆分时候如遇上特殊字符无法拆分,是需要转义字符的问题。

其他操作
Public String toLowerCase()    转小写
Public String toUpperCase()    转大写
Public String trim()   去除两边的空格
Public int length()     长度


Equals和equalsIgnoreCase的区别:
public class demo1 {
    public static void main(String[] args) {
        String a = "SSS";
        String b = "sss";
        boolean num = a.equals(b);//这个是区分大小写==》equals
        System.out.println(num);
        boolean num1 = a.equalsIgnoreCase(b);//这个是不区分大小写==》equalsIgnoreCase
        System.out.println(num1);
    }
}
字符串的一些方法:
public class demo2 {
    public static void main(String[] args) {
        String a = "jisngmmsfpdps";
        int length = a.length();//.length方法是算出字符串长度
        System.out.println("该字符串长度为:"+a.length());
        String concat = a.concat("HelloWORLD");//.concat方法是起拼接连接作用,和“+”类似
        System.out.println(concat);
        char c = a.charAt(5);//.charAt方法是算出字符串索引编号为5的字符
        System.out.println(c);
        int d = a.indexOf("u");//.indexOf方法是算出字符串中具体一个字符的索引编号是多少;没有的话显示值为:-1
        System.out.println(d);

    }
}
替换(replace)的使用:
public class demo3 {
    public static void main(String[] args) {
        char[] a = {'A','B','C','D'};
        String b = new String(a);
        String c = "asdfghj";
        char[] d = c.toCharArray();
        System.out.println(d[2]);
        String f = "中国很大,我想去看看";
        String replace = f.replace("我想去看看", "有时间再去看看吧");
        System.out.println(f);
        System.out.println(replace);
    }
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马