Using valueOf() Instead of toString() August 7, 2017 The valueOf()Â method is useful when you do not know the value contained and it might throw a NullPointerException. It returns null and you can handle the same in your code