public class Main {
public static void main(String[] args) {
String[] words = {"The", "quick", "brown", "fox", ",", "jumps", "over", "the", "lazy", "dog", "."};
String concatenatedString = "";
for (String word : words) {
concatenatedString += word + " ";
}
System.out.println(concatenatedString);
}
}
I am trying to concatenate all the words from a string array in a single string, and the output I get is like this : "The quick brown fox , jumps over the lazy dog ."
I would want the spaces before punctuation marks to be removed so the output could look like this : "The quick brown fox, jumps over the lazy dog." Any idea how could I do that?