Since String.split matches on a regular expression basis, @. means that it searches for two characters in a string (not one character once). And . in regular expressions, it is a special symbol meaning "anything":
@. = "@ and then any character"
In your case, this matches "@g" and not a period.
Instead, you want:
String[] pattens = email.split("[@.]");
The square brackets [] create a character class that represents all valid characters that can match a single position. So you need to match " @ " or " . ". Symbol . no need to escape inside a character class.
source share