how to create a sentence or a paragraph on String[] Array | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

16th Nov 2017, 7:27 PM
Nazhan Harzula
Nazhan Harzula - avatar
2 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.
16th Nov 2017, 8:07 PM
Rrestoring faith
Rrestoring faith - avatar
+ 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);
16th Nov 2017, 7:48 PM
Witty Phantom
Witty Phantom - avatar