Tuesday, February 3, 2026

java string value + int is a string or not?

When a Java String value is concatenated with an int value using the + operator, the result is a String.
This behavior is due to Java's rules for the + operator:
  1. If either operand is a String, the other operand is automatically converted to its string representation (e.g., the integer 10 becomes "10").
  2. The operator then performs string concatenation.

Example:

 String value = "The answer is: ";

int number = 42;


String result = value + number;


// The value of 'result' will be the string "The answer is: 42"


No comments:

Post a Comment

Class IX IT notes: Part A, Unit 1, Session 3.

 IT notes class 9 Part A Unit 1: COMMUNICATION SKILLS session 3: VISUAL AND WRITTEN METHODS OF COMMUNICATION Q1. What is Visual Communicatio...