在分割电子邮件ID时获取此按摩[Ljava.lang.String;@776a35.
为什么我不明白。
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]);
}
答案 0 :(得分:2)
在java中,您无法打印数组(这是您尝试时获得的输出)。您必须使用Arrays.toString()
。
String[] For_split_email=email.split("[@._]");
System.out.println("splited emails----------"
+ Arrays.toString(For_split_email));
我很确定您发布的代码不是产生该输出的代码。
答案 1 :(得分:2)
您的代码非常适合我。但它在for循环中应该是j <= For_split_email.length - 1
。
String email = "test@test.de";
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]);
}
输出:
splited emails----------test
splited emails----------test
splited emails----------de
答案 2 :(得分:1)
我不确定您给出的电子邮件内容。如果您想按照问题中提到的那样拆分电子邮件,请尝试这样做,
String email ="test@gmail.com";
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]);
}
答案 3 :(得分:1)
你可以尝试
String str = "example@email.com";
String split_first = str.substring(0,str.indexOf("@"));
String split_second = str.substring(str.indexOf("@")+1);
或
String email = "example@email.com";
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]);
}
}
答案 4 :(得分:0)
试试吧
String email = "raju@gamil.com";
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]);
}