Raghu
Raghu

Reputation: 23

How to split email id in java

While splitting an email id getting this massage [Ljava.lang.String;@776a35. why i cant understand.

        String[] For_split_email=email.split("[@._]");
        for (int j = 0; j <= For_split_email.length - 1; j++) {
        System.out.println("splited emails----------"+For_split_email[j]);
         }

Upvotes: 0

Views: 13158

Answers (5)

Bhaskor Jyoti Sarmah
Bhaskor Jyoti Sarmah

Reputation: 126

You can try

String str = "[email protected]";
String split_first = str.substring(0,str.indexOf("@"));
String split_second = str.substring(str.indexOf("@")+1);

or

String email = "[email protected]";
String[] For_split_email=email.split("[@|\\.|_]");
        for (int j = 0; j <= For_split_email.length - 1; j++) {
        System.out.println("splited emails----------"+For_split_email[j]);
         }
    }

Upvotes: 2

kai
kai

Reputation: 6887

You code is perfectly working for me. But it should be j <= For_split_email.length - 1 in the for loop.

    String email = "[email protected]";
    String[] For_split_email = email.split("[@._]");
    for (int j = 0; j <= For_split_email.length - 1; j++)
    {
        System.out.println("splited emails----------" + For_split_email[j]);
    }

Output:

splited emails----------test
splited emails----------test
splited emails----------de

Upvotes: 3

Jamsheer
Jamsheer

Reputation: 3753

I am not sure what you given as the content of email.If you want to split the email as you mentioned in the question please try like this ,

    String email ="[email protected]";
    String[] For_split_email=email.split("[@._]");
    for (int j = 0; j <= For_split_email.length - 1; j++) {
       System.out.println("splited emails----------"+For_split_email[j]);
     }

Upvotes: 1

m suresh
m suresh

Reputation: 659

try it

String email = "[email protected]";
String[] For_split_email = email.split("[@._]");
for (int j = 0; j <= For_split_email.length - 1; j++)
{
    System.out.println("splited emails data----------" + For_split_email[j]);
}

Upvotes: 0

Bohemian
Bohemian

Reputation: 425198

In java, you can't print an array (that's the output you get when you try). You must use Arrays.toString().

String[] For_split_email=email.split("[@._]");
System.out.println("splited emails----------"
    + Arrays.toString(For_split_email));

I'm pretty sure the code you posted isn't the code that produced that output.

Upvotes: 2

Related Questions