1

this line of code is messing with me,

String[] parseEmailDomain = parseEmail[1].split(".");

When i do System.out.println(parseEmailDomain.length) the size of the array ends up being 0 BUT the output of System.out.println(parseEmail[1]) is

cs.uh.edu

anyone have any idea as to why when I try to split the array, it doesn't split it but when I try to just output the array it outputs perfectly fine?

I am able to do this

String[] parseEmail = parseLn[i].split("@");

the out put of System.out.println(parseEmail[0]); is hanak and parseLn is an entire line from a text file

donfuxx
  • 11,277
  • 6
  • 44
  • 76
user3369494
  • 123
  • 11

3 Answers3

9

because . will match anything because split takes a regex!

you will need to escape the dot with \:

 String[] parseEmailDomain = parseEmail[1].split("\\.");

See also the related answer here: Java RegEx meta character (.) and ordinary dot?

Community
  • 1
  • 1
donfuxx
  • 11,277
  • 6
  • 44
  • 76
2

Try to put two backslash's before the dot:

String[] parseEmailDomain = parseEmail[1].split("\\.");

A dot in regexes means any character.

hichris123
  • 10,145
  • 15
  • 56
  • 70
Ivo Fernandes
  • 104
  • 1
  • 3
1

parameter of 'split(String)' is actually regular expression so use Scanner or StringTokenizer instead

Bitman
  • 1,996
  • 1
  • 15
  • 18