Java Is Always Pass-By-Value
The confusion with how Java handles references stems from how it handles objects. One such instance is the String builder, at first appears as if it is pass-by-reference but what java is really doing is updating the object that the string buffer sb references. It’s creating a new String Builder in the method (adhering to pass-by-value), but that new String Builder references the same object in memory.
public static void main(String[] args){
StringBuilder sb = new StringBuilder(“pass”);
mutate(sb);
System.out.println(sb);
//prints passvalue
}
private static void mutate(StringBuilder sb){
sb.append(“value”)
}