String str = ""; // in this case str references a String instance, albeit an empty string instance. String str = null; // str does not refer to a String instance. In my opinion the former is more "correct" than the latter. But it all depends on the conventions agreed upon by the rest of your program. -Barry [ September 29, 2002: Message edited by: Barry Gaunt ]
In my opinion, it is useless to declare a String as String str=""; What you are doing is allocating a useless String object. Strings are immutable objects. So what will happen next is that you will recreate another String while writing str="Toto". The use of "" is however optimized since it belongs to the String pool. If you need to know if your String has been allocated before then a simple test (str==null) is better than str.equals("") (the latter being worse worse than str.length()==0). W.
Joined: Aug 03, 2002
So, James, take your pick. I do like my references pointing somewhere, though. -Barry