split() | returns wrong result

The required parameter of the split method is a regular expression, and | is a special symbol in the regular expression, which needs to be escaped


public static void main(String[] args) {
    // TODO Auto-generated method stub
    String [] b = "a |b|c".split("\\|");
    System.out.println(b[0]);
    System.out.println(b[1]);
    System.out.println(b[2]) ;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326359869&siteId=291194637