Java Community | Help. Code. Learn.JC|HCL
Java Community | Help. Code. Learn.โ€ข15mo agoโ€ข
13 replies
theash2473

Adding character/s to a string has two different variations.

If you add two characters to a string you get an int as an output but when you add one character it works.
Please explain. Here is an example with output for reference.
String str = "eeksforGeeks";

        // Inserting at the beginning
        String str2 ='[' +'['+ str;

        // Print and display the above string
        System.out.println(str2);
      str2='['+str;
      System.out.println(str2);


Output-:
182eeksforGeeks
[eeksforGeeks
Was this page helpful?