java - String class split method -
this question has answer here:
i have written 1 java thread split string
public void run() { string input="sasi|maran|rishabh"; string arr[]=input.split("|"); (int = 0; < arr.length; i++) { try{ system.out.println(arr[i]); thread.sleep(1000); }catch(exception e){ e.printstacktrace(); } } }
output expectation:
sasi rishabh maran
but output getting :
s s | m r n | r s h b h
string#split method takes regex argument. |
meta character, , it's have special meaning in regex. escape it.
string arr[]=input.split("\\|");
Comments
Post a Comment