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

We have a facts array as a String, and we have randomNumber as int. Why Android did not show mistake in this case?

I am watching all videos again right now and come to this question. We have a facts array as a String, and we have randomNumber as int. Why Android did not show mistake in this case? Because they are incompatible data types, right? Or I do not know something here?

2 Answers

Hello Adilet Zhusupbekov,

An Array can hold many different types of Objects. For example:

//Array of Integers
int[] intArray = {1, 2, 3, 4};

//Array of Strings
String[] stringArray = {"Hello", "Goodbye", "Good morning"};

Arrays use index's to be able to get the data in a certain location in the array. No matter what the type of array to access the data based on the index we need to pass in a integer.

//Array of Integers
int[] intArray = {1, 2, 3, 4};

//Array of Strings
String[] stringArray = {"Hello", "Goodbye", "Good morning"};

stringArray[0]; // This would give us the String "Hello"
stringArray[1]; // This would give us the String "Goodbye"
string Array[2]; // This would give us the String "Good morning"

Hope this helps!

Thank you, Sam!