0
how to create a sentence or a paragraph on String[] Array
I have an array of type strings with the contents in it a split-spoken word. hence from that whether the solved words can be recreated into a sentence or paragraph on the like as the story example : String[] array = {"I", "am", "superman", "can", "i", "fly" , "through", "the", "window", "because" , "i", "need" , "to", "show", "the" , "world", "that" , " i " , "am" , "superman"}; expectations = I am superman. can i fly through the window i need to show the world that i am superman
3 Answers
+ 3
StringBuilder:
StringBuilder sentence = new StringBuilder();
for(String i : array)
sentence.append(i);
System.out.println(sentence);
Arrays:
String sentence = Arrays.toString(array);
These are pretty much equivalent, though you will have the sentence surrounded in square brackets with the toString() method.
+ 1
Not a Java professional so can't think of a better way than this:
String str = "";
for(int i = 0; i<array.length; i++){
str += array[i];
}
System.out.println(str);