I am trying to split a string using the Split function in java
String empName="employee name | employee Email"; String[] empDetails=empName.split("|");
he gives me the result as
empDetails[0]="e"; empDetails[1]="m"; empDetails[2]="p"; empDetails[3]="l"; empDetails[4]="o"; empDetails[5]="y"; empDetails[6]="e"; empDetails[7]="e"; . . .
but when i try to execute the code
String empName="employee name - employee Email"; String[] empDetails=empName.split("-");
it gives me
empDetails[0]="employee name "; empDetails[1]=" employee Email";
why the java split function cannot split the string separated by "|"
source share