Splitting a String with the pipe symbol as delimiter

前端 未结 6 1947
情话喂你
情话喂你 2021-01-17 10:25

Why is it that in the following, the output is [] and not [1]?

String input=\"1|2|3\";
String[] values= input.split(\"|\");
System.         


        
6条回答
  •  滥情空心
    2021-01-17 10:51

    Try to escape that character:

    String input="1|2|3";
    String[] values= input.split("\\|");
    System.out.println("[" + values[0] + "]");
    

提交回复
热议问题