This is more of theory question. I have this piece of code:
String[] contacts = new String[10];
for (int x = 0; x < contacts.length; x++)
{
contacts[x] = "Person" + x;
System.out.println(contacts[x]);
}
I understand that arrays can only have one type but I have concatenated the variable x (which is an int) on to the end of the String and stored this into an array. However when I try to do this int based array it doesn't like it which makes sense because you can't mix types in an array that is declared to be holding int variables. Im confused because you can add Boolean as well to the end of the statement.
contacts[x] = "Person" + x + false
As long as the array starts with a String you can get away with it. Is this because the String in an object itself? I'm really sorry if this is an obvious question. I believe this is related to this question but it doesn't quite answer it to my satisfaction Multiple type array