What will be displayed to console after the following code is executed?

public class Test {
    public static void main(String[] args) {
        String s = new String("ssssss");
        StringBuffer sb = new StringBuffer("bbbbbb");
        s.concat("-aaa");
        sb.append("-aaa");
        System.out.println(s);
        System.out.println(sb);
    }
}
Explanation
s.concat() will not change the value of s variable, since String is an "immutable" object unlike the StringBuffer, which implements a mutable string

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback