String.valueOf() X toString()

E ae galera,

O que é mais rapido ou mais “bonito” :

StringBuffer strB = new StringBuffer();
esse:
String.valueOf(strB); ???
ou esse
strB.toString(); ????

Valew !
[]´s a todos

Eu sempre uso sb.toString().

Sem duvida sb.toString()…

Ah, e veja soh…

/*
 * @(#)String.java	1.159 03/01/23
 *
 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
...

    /**
     * Returns the string representation of the <code>Object</code> argument.
     *
     * @param   obj   an <code>Object</code>.
     * @return  if the argument is <code>null</code>, then a string equal to
     *          <code>"null"</code>; otherwise, the value of
     *          <code>obj.toString()</code> is returned.
     * @see     java.lang.Object#toString()
     */
    public static String valueOf(Object obj) {
	     return (obj == null) ? "null" : obj.toString();
    }
...

ta…
mas se o obj for nulo, com toString() daria um NullPointException
e com String.valueOf() não teria que fazer um if(obj != null) antes.

certo ?

[]´s

Mas você receberia a String “null”, o que pode não ser o desejado na sua app, certo?