Search code examples
javastringtype-conversioninteger

Integer.toString(int i) vs String.valueOf(int i) in Java


I am wondering why the method String.valueOf(int i) exists ? I am using this method to convert int into String and just discovered the Integer.toString(int i) method.

After looking the implementation of these methods I saw that the first one is calling the second one. As a consequence all my calls to String.valueOf(int i) involve one more call than directly calling Integer.toString(int i)


Solution

  • Just two different ways of doing the same thing. It may be a historical reason (can't remember if one came before the other).