My requirement is to replace all commas in a string with newline.
Example:
AA,BB,CC
should represent as
AA
BB
CC
here's my implementation to replace commas with newline,
public String getFormattedEmails(String emailList) {
List<String> emailTokens = Arrays.asList(emailList.split(","));
String emails = "";
StringBuilder stringBuilder = new StringBuilder();
String delimiter = "";
for(String email : emailTokens){
stringBuilder.append(delimiter);
stringBuilder.append(email);
delimiter = "\n";
}
emails = stringBuilder.toString();
return emails;
}
this method replaces all commas with a space. can anyone point me where did I go wrong?
this method replaces all commas with a space
- really? I don't see any space added to the output, besides those that might be contained in the individual tokens.