java - PatternSyntaxException when splitting string at "*" character -


every time try split string "hello*world" using s.split("*"); patternsyntaxexception.

i have tried using s.split("\*"); gives me error. im sure simple.

how stop this?

the split method takes regular expression argument, not normal string. * has special meaning in regular expressions. if want split on literal *, have escape backslash. backslash escape character in java string literals, have escape backslash using 2 backslashes:

s.split("\\*") 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -