Android Build a Simple Android App with Java Basic Android Programming Generating a Random Number

Jisan Reza
Jisan Reza
8,089 Points

from what I see in min 3:44 String + int = String ?

String + int = String

2 Answers

If you are interested there is an alternative way of doing the conversion beside String + int. which is calling this method String.valueOf(int i) This method will return a String data type

andren
andren
28,391 Points

That is correct. When you concatenate (use the + operator on) two values and one of them is a String it will try to convert the other value to a String as well before it combines them.

It doesn't matter if it is int + String or String + int or even some other datatype than int, as long as one of the values is a String it will try to convert the other value into a String as well.