1

Hey there wonderful people. I am an active Java student for months now, but still sometimes I come across stuff I am yet to understand. Here the goal was to split an email address into three parts: the address, the domain and the country code at the end.

I came up with the code below, but it throws an "ArrayIndexOutOfBoundsException" error. I understand this is an issue with the second array, but I don't understand the cause, nor I have another idea for this problem.

I would greatly appreciate your help and insight.

    String lineOne = "example@gmail.com";
    String[] arrayOne = line.split("@");

    String lineTwo = arrayOne[1];
    String[] arrayTwo = lineTwo.split(".");

    System.out.println(arrayTwo[0]);
    System.out.println(arrayTwo[1]);
Dave Newton
  • 158,873
  • 26
  • 254
  • 302

0 Answers0