Java program to concatenate the given strings using concat() method
KW.java
class KW
{
    public static void main(String args[])
    {
        String s="HELLO";
        s=s.concat(" WORLD");
        System.out.println(s);
    }
}
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW HELLO WORLD kodingwindow@kw:~$
Java program to concatenate the given strings by passing object as a value
KW.java
class KW
{
    public static void main(String args[])
    {
        String s1="HELLO";
        String s2="WORLD";
        System.out.println(s1+s2);
    }
}
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW HELLO WORLD kodingwindow@kw:~$
Advertisement