This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi, The reason is obvious, in the first program, you create the String object, but in the second one, you are creating the array object not the individual string objects, you should get identical behavior if you create the array objects also.
This outputs a blank string. This is because of the definition of String constructor of Java which initilizes a String objects as empty character sequences. Well as the String objects are immtable so this constructor has no relevance.
In this case you are defining a String Array. Now this leads to blank String objects but, two null Array objects. Thus it results into two null String array objects. hence the output for the loop is null.