Java is not splitting a String correctly [duplicate]

1

I am trying to split a String using the following character "|" But java is understood to be to divide letter by letter.

        List<Curso> cursos = new ArrayList<Curso>();
        List<String> pacotes = Arrays.asList("Criança-1,2,3-1,00|Preparatório Primeiro Emprego-4,5,6,7,8,9-139,99".split("|"));
    System.out.println(pacotes.toString()); //I/System.out: [, C, r, i, a, n, ç, a, -, 1, ,, 2, ,, 3, -, 1, ,, 0, 0, |, P, r, e, p, a, r, a, t, ó, r, i, o,  , P, r, i, m, e, i, r, o,  , E, m, p, r, e, g, o, -, 4, ,, 5, ,, 6, ,, 7, ,, 8, ,, 9, -, 1, 3, 9, ,, 9, 9]

Can anyone help me?

    
asked by anonymous 07.08.2017 / 21:06

1 answer

7

The "|" pipe is a special character of the regex. So, you should escape it:

split("\|");
    
07.08.2017 / 21:09