Related Articles

Related Articles

Java String concat() with examples
  • Last Updated : 17 Apr, 2019

The Java String concat() method concatenates one string to the end of another string.This method returns a string with the value of the string passed into the method, appended to the end of the string.
Signature:

 public String concat(String anostr)   

Parameter:

 anostr- string to be concatenated at the
  end of the another string.

Return:

  combination of two strings is returned.

Example:To show working of concat() method

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// working of concat() method
  
class Gfg {
    public static void main(String args[])
    {
        String s = "Gfg";
        s = s.concat("! is the best.");
        System.out.println(s);
    }
}

chevron_right


Output:

Gfg! is the best.
filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// working of concat() method
  
class Gfg {
    public static void main(String args[])
    {
        String s = "Gfg";
  
        // We must explicitly assign result
        // of s.concat() to s.  Since not 
        // assigned to s, s does not change.
        s.concat("! is the best.");
  
        System.out.println(s);
    }
}

chevron_right


Output:

Gfg

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up
Recommended Articles
Page :