java中spilt()特殊符号:. | * \ ] [(点、竖、星号、斜线、中括号)

对点进行处理

@Test
public void test0001(){
    String str = "asczscx.xsa";
    String[] split = str.split("[.]");
    for (String s : split){
        System.out.println(s);
    }
}

输出

asczscx
xsa

对竖进行处理

@Test
public void test0001(){
    String str = "asczscx|xsa";
    String[] split = str.split("\\|");
    for (String s : split){
        System.out.println(s);
    }
}

输出

asczscx
xsa

对星号进行处理

@Test
public void test0001(){
	String str = "asczscx*xsa";
    String[] split = str.split("\\*");
    for (String s : split){
        System.out.println(s);
    }
}

输出

asczscx
xsa

对斜线进行处理

@Test
public void test0001(){
    String str = "asczscx\\xsa";
    String[] split = str.split("\\\\");
    for (String s : split){
        System.out.println(s);
    }
}

输出

asczscx
xsa

对中括号的进行处理

@Test
public void test0001(){
    String str = "asczscx[]xsa";
    String[] split = str.split("\\[\\]");
    for (String s : split){
        System.out.println(s);
    }
}

输出

asczscx
xsa

你可能感兴趣的:(#,常用(错/忘)小知识,java,开发语言,jvm)