试图用逗号分割java中的字符串。
String example = "This,Is, An, Example, Split, Palm Bay"
example.split(",");
分裂但一旦碰到空白就停止,所以我得到的 String[] 只包含“This”和“Is”。
以下是我遇到问题的代码部分,如果我在扫描仪的输入中有任何空白,则拆分会停在那里。
Scanner scanner = new Scanner(System.in);
String customerDetails = scanner.next();
String[] details = customerDetails.split(",");
if(details.length < 5) {
for(int i = 0; i < details.length; i++) {
System.out.println(details[i]);
}
System.out.println("Cannot complete your request, it appears that you have not entered enough information");
return;
}
if(directory.addCustomer(new CustomerType(details[0], details[1], details[2], details[3], details[4])))