Java Program showing the use of string functions like concat(),replace() and trim()…


This java code will show you the use of some of the string functions like concat(), replace() and trim().

class StringFun
{
public static void main(String args [])
{
String s1,s2;

//String Concat
s1=”Hello”;
s2=s1.concat(” java”);

System.out.println(s1);
System.out.println(s2);

//String Replace

String s3;
s3=s1.replace(‘l’,’w’);
System.out.println(s1);
System.out.println(s3);

//Trim
String s4,s5;
s4=” Hello World “;
s5=s4.trim();
System.out.println(s4);
System.out.println(s5);
}
}

Add Comment