Intercept whether the string contains commas and intercept single or multiple mobile phone numbers.
public class Test {
public static void main(String[] args) {
String mobile = "15688888888,13799999999,15266666666";
// String mobile = "15688888888";
String[] mobiles = new String[1];
if (mobile.contains(",")) {
mobiles = mobile.split(",");
} else if (mobile.contains(" ")) {
mobiles = mobile.split(" ");
}else {
mobiles[0] = mobile;
}
int i = 0;
for (String telephone : mobiles) {
i++;
System.out.println(telephone);
}
}
}
Print the result if the string contains commas. Print
the result if the string does not contain commas.