Monday, February 28, 2011

Split a String with Dot "." in JAVA

In JAVA we can split a String with Dot "." using a split() function. But it can be done in a different way as compared to other characters. Dot "." is a reserved character in regular expression, hence it will not treat the split on dot the same way.

Following code can be used to split a string by dot.

String stringWithDot = ""; 
String[] stringArray = stringWithDot.split("\\.");

Double backslash will do the work where one slash is work as a escape character.


No comments: