Manipulating IP addresses - split string on '.' character

java, regex

Solution

You need to escape the "." as `split` takes a regex. But you also need to escape the escape as "\." won't work in a java `String`:

String [] split = address.split("\\.");

This is because the backslash in a java `String` denotes the beginning of a character literal.

Problem

``` String address = "192.168.1.1"; ``` I want to split the address and the delimiter is the point. So I used this code: ``` String [] split = address.split("."); ``` But it didn't work, when I used this code it works: ``` String [] split = address.split("\\."); ``` so why splitting the dot in IPv4 address is done like this : `("\\.")` ?

Original source