top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is difference and similarities between concat() and append() in java,given reason and example?

+1 vote
1,938 views
What is difference and similarities between concat() and append() in java,given reason and example?
posted Jul 1, 2017 by Ajay Kumar

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

String concat() method concatenate or join two strings like String s1 and String s2 and return a third string(s3) as a result.
String s1="Uttar";
String s2="Pradesh";
String s3=s1.concat(s2);

String concat() method is immutable methods. In this method content of sting variable are not modify.
But append() method is mutable method of StingBuffer class. in this method content of StringBuffer class variable are modify.
StringBuffer sb=new StringBuffer("Uni");
sb.append("versity");

Preceding statements produce:"University".

answer Jul 2, 2017 by Saurabh Pandey
Similar Questions
+2 votes

Given two strings, append them together (known as "concatenation") and return the result. However, if the concatenation creates a double-char, then omit one of the chars. If the inputs are "Mark" and "Kate" then the output should be "markate". (The output should be in lowercase).

...