Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Simple Android App (2014) Coding the Fun Facts Properties of Arrays

Eleni Minadaki
Eleni Minadaki
3,687 Points

How can i write large text in a string array?

Hi!would like to ask if there is an ability to write large text in a String array.To explain better instead to copy- paste the text from the lesson where is 1 line each array's position "coding the fun facts" i would like to write 4-5 lines(try to make an app and is needed)don't know at all a way to make... Thanks a lot for any help!!

Fabian Gmeiner
Fabian Gmeiner
6,574 Points

Do you want each line to be a separate or just a wordwrap ?

The Java - Symbol for a wordwrap is \n .

3 Answers

Eleni Minadaki
Eleni Minadaki
3,687 Points

yes,you understand what i mean have to give you some more details,the problem is that when i write this: String [] facts = {

                        "Ants stretch when they wake up in the morning.",
                        "Ostriches can run faster than horses.",
                        "Olympic gold medals are actually made mostly of silver.",
                        "You are born with 300 bones; by the time you are an adult you will have 206.",
                        "It takes about 8 minutes for light from the Sun to reach Earth.",
                        "Some bamboo plants can grow almost a meter in just one day.",
                        "The state of Florida is bigger than England.",
                        "Some penguins can leap 2-3 meters out of the water.",
                        "On average, it takes 66 days to form a new habit.",
                        "Mammoths still walked the earth when the Great Pyramid was being built."};
            String fact = "";
            Random randomGenerator = new Random();
            int randomNumber = randomGenerator.nextInt(10);

BUT want instead 1 line be 5-7 lines 10 times(10 positions in array) the text of first position for example should be "blablablabla.........................\n"+ "blablablablablabla...........\n"+ "blablablablablabla...........\n"+ "blablablablablabla...........\n"; right? and the second one just i let some space and write again with the same way? Thanks for your patient!

Eleni Minadaki
Eleni Minadaki
3,687 Points

Hi Fabian ,thank you for the quick response,I would like to make a string array with 10 positions and each one will have a text from about 7 lines. Hope this help to understand!

Fabian Gmeiner
Fabian Gmeiner
6,574 Points

After watching the video again I think I know what you mean.

String[] array = { "This is just one line", "Because of this: \n These are to lines but one String ", ...};

The String in each element can be as long as you want it to be.

If this is not what you are trying to do, please explain it in gerater detail.

Eleni Minadaki
Eleni Minadaki
3,687 Points

Found it!thank you for your help!