[java] Integer.toString(int i) vs String.valueOf(int i)

toString()

  1. is present in Object class, generally overrided in derived class
  2. typecast to appropriate class is necessary to call toString() method.

valueOf()

  1. Overloaded static method present in String class.
  2. handles primitive types as well as object types.

    Integer a = null;
    System.out.println(Integer.toString()) ; NUll pointer exception
    System.out.println(String.valueOf() ; give NULL as value
    

check this link its very good. http://code4reference.com/2013/06/which-one-is-better-valueof-or-tostring/