Java 实例 - 字符串分割

Posted 猪小胖

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java 实例 - 字符串分割相关的知识,希望对你有一定的参考价值。

package string;

public class split {
    public static void main(String[] args) {
        /**
         * 字符串的分割
         */
        String str = "www.baidu.com";
        String[] temp = str.split("\\.");// "."和“|”都需要加上\\转译
        for (int i = 0; i < temp.length; i++) {
            System.out.println(temp[i]);
        }
        System.out.println("============使用for each==========");
        String str1 = "abc-cdef-ghij";
        String[] temp1 = str1.split("-");
        for (String x : temp1) {
            System.out.println(x);
        }
    }

}

 

以上是关于Java 实例 - 字符串分割的主要内容,如果未能解决你的问题,请参考以下文章