by asn0 · 5y ago · 0 comments
var mutableVar = "Foo"
final var immutableVar = "Bar" final ArrayList<String> foo = new ArrayList<>();
foo.add("Foo"); // Compiles and runs - this is mutation
foo = new ArrayList<>(); // Compiler error - this is re-assignment
In your example, both Strings are immutable, since Java Strings are always immutable.