Java String Concatenation with Other Data Types.


If you try to concatenate strings using concat() method, you can concat variables of string data type only.

To concatenate strings with other data type you need to use the ‘+’ operator.

Example

public class Test {
   public static void main(String args[]){
      String st1 = "Hello";
      int data = 230;
      String res = st1+data;
      System.out.println(res);
   }
}

Output

Hello230

Updated on: 26-Feb-2020

781 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements