Splitting a Java String by the pipe symbol using split(“|”)

前端 未结 7 874
生来不讨喜
生来不讨喜 2020-11-21 23:32

The Java official documentation states:

The string \"boo:and:foo\", for example, yields the following results with these expressions Regex Result :

相关标签:
7条回答
  • 2020-11-22 00:28

    Use this code:

    public static void main(String[] args) {
        String test = "A|B|C||D";
    
        String[] result = test.split("\\|");
    
        for (String s : result) {
            System.out.println(">" + s + "<");
        }
    }
    
    0 讨论(0)
提交回复
热议问题