Meaning of + symbol with Strings in Java println statement

后端 未结 7 963
孤独总比滥情好
孤独总比滥情好 2021-01-16 09:57

I\'m new to Java. What does the below mean?

(addition) + sign in println

System.out.println ("Count is: " + i);

7条回答
  •  独厮守ぢ
    2021-01-16 10:05

    In that context, the + operator is acting as the string concatenation operator. It acts as a different operator in the context of two integral types, where addition will be performed.

    Assuming i is an integral type, it'll be converted to a String and then added on to the end of a new string beginning with "Count is: ". That new string is then printed.

    ie. If i had the value 0, it'd be the same as:

    "Count is: " + "0"
    

    Which would be:

    "Count is: 0"
    

提交回复
热议问题