This program
public class OddBehavior {
public static void main(String[] args){
String[] words = new String[3];
words[0] += "ify";
System.out.println(words[0]);
}
}
has the following output:
I initialized an array of 3 String
s, which I thought would be null
. But by adding the string "ify" to the end of words[0]
, the words[0]
got the value "nullify"
, i.e. it already contained the String "null"
(the String
, not the value null
!)