I know that String
is immutable and it's value can't be changed, but why does the value of the below StringBuffer
doesn't change when sent like a method parameter. From my understanding it should have changed with the new value "bb". Thank you for your help.
class Ideone {
public static void main (String[] args) {
String s = "aa";
StringBuffer sb = new StringBuffer("aa");
modify(s, "bb");
modify2(sb, "bb");
System.out.println(s);
System.out.println(sb);
}
public static void modify(String s, String ss) {
s = ss;
}
public static void modify2(StringBuffer sb, String ss) {
sb = new StringBuffer(ss);
}
}