1

I need to be able to split a single word string like "x.y" into an array of size 2 where the "." occurs, so the array would look like ["x", "y"]. What I've tried is:

String word = "hello.world";
String[] split = word.split(".")
return split.length == 2;

but this seems to just return an empty array (false). How would I go about doing this? Thanks.

lewis.k
  • 23
  • 1
  • 3

1 Answers1

1

Repalce this

String[] split = word.split(".")

with

String[] split = word.split("\\.")

. (dot) has a special meaning in regex so you need to escape it if you want to use it as a literal to split.

Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136