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

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -