Java String Concatenation with Other Data Types.

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 09-Feb-2018 10:39:29
Advertisements