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 : ("\\.")
?
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.
You should split like this, small tip use Pattern.compile as well
String address = "192.168.1.1";
String[] split = address.split("\\.");// you can replace it with private static final Pattern.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With