0

I want to split a string three times.

This is the string: 21.06.2016;00:30

My function looks like this:

String[] split = dateV.split(";");
String[] date = split[0].split(".");
String[] time = split[1].split(":");

date[0] should contain "21" after all

So the first part works great.

My two strings are

split[0] = 21.06.2016
split[1] = 00:30

But when I call split[0].split("."); I get a

java.lang.ArrayIndexOutOfBoundsException: length=0; index=0

Can somebody tell me why?

Zoker
  • 2,020
  • 5
  • 32
  • 53

1 Answers1

6

String.split uses regular expressions to do the split, and a dot is a special character when regular expressions are used.

To split using a dot, you need to escape it like this

String[] date = split[0].split("\\.");
Cristian Meneses
  • 4,013
  • 17
  • 32