java - Split String not working properly with (|) operator -


this question has answer here:

i trying split string using '|' operator unable complete operation.

i getting wrong output.

i using below code :

public static void main(string[] args) {         string str = "c|9374052566|tfname|tlname|01-10-1988|test@gmail.com|234897238794";         string array[] = str.split("|");          (string str_ : array) {             system.out.println(str_);         }       } }  //produce output         c         |         9         3         7         4         0         5         2         5         6         6         |         t         f         n                 m         e         |         t         l         n                 m         e         |         0         1         -         1         0         -         1         9         8         8         |         t         e         s         t         @         g         m                         l         .         c         o         m         |         2         3         4         8         9         7         2         3         8         7         9         4          //expected output         c         9374052566         tfname         tlname         01-10-1988         test@gmail.com         234897238794 

what wrong program?

split method takes regular expression , | reserved character, used or operator in regular expression.

use \\| escape it.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -