> NB my stanza for repeatedly writing non-null checks is: > if( stringToCompare == null ) > stringToCompare = ""; > if( stringToCompare.equals("something") ) { > ... > }
becomes: 0 aload_0 1 ifnonnull 7 4 ldc #2 <String ""> 6 astore_0 7 aload_0 8 ldc #3 <String "something"> 10 invokevirtual #4 <Method boolean equals(java.lang.Object)> 13 ifeq ... ... if("something".equals(stringToCompare) ) { ; } becomes: 0 ldc #3 <String "something"> 2 aload_0 3 invokevirtual #4 <Method boolean equals(java.lang.Object)> 6 ifeq ... ... In terms of clock cycles, if the value to be compared is null, your way is 20% slower. It is about 10% slower if the value to be compared is "" or a non-matching valid string. It is only marginally slower if the values are equal. --- Noel