What does this snippet of code mean?
int value;
if (value > 0)
String input = "" + value;
It is converting value to a string. "" + value is very similar to value.toString(). The "" means the compiler is looking for a string after the +, so when it sees value in that space, it automatically calls value.toString() to produce the string result.
Integer.toString(value), since it's an int, but the idea is the same (+1).+' with strings is a quite bad practice. The developer should use value.toString() or a StringBuilder (at least).Integer.toString() approach is to be preferred.String input = "" + value; value is an integer type. adding it to empty string-"" just making it a string. Suppose value = 3, then ""+value will be "3"
Edit: Forgot to mention about String.valueOf(val) function, another static utility method to convert almost all primitive type to String.
Compiler know how to add an integer with some string value. So in the code rather calling directly the integer to string conversion method. The coder generates an constant string ""(having no value in it) and then call concatenation operator(+) overloaded method to add and cast the integer into string value.
intinto aString.