随笔都是学习笔记
随笔仅供参考,为避免笔记中可能出现的错误误导他人,请勿转载。
package Demo_1_22_String;

public class StringSplit {
    public static void main(String[] args) {
        String str = "www ccc com";
        // 全部拆分
        String result[] = str.split(" ");   // 按照指定参数来进行字符串的拆分

        for (String s : result) {
            System.out.println("result = " + s);
        }
//        for (int i = 0; i < result.length; i++) {
//            System.out.println(result[i]);
//        }
        System.out.println("=============================");
        // 拆分两次,拆一次后就结束
        String result1[] = str.split(" ",2);   // 按照指定参数来进行字符串的拆分
        for (String s : result1) {
            System.out.println("result1 = " + s);
        }

        System.out.println("=============================");
        String str1 = "www.ccc.com";
        // 特俗字符拆分
        String result2[] = str1.split("\\.");   // 转义拆分
        for (String s : result2) {
            System.out.println("result2 = " + s);
        }

    }
}

 

posted on 2022-01-22 14:17  时间完全不够用啊  阅读(78)  评论(0编辑  收藏  举报