Is there any way of appending StringBuilders just "temporarily"?
Basically what I want is the same functionality and behaviour of String.concat()
, but we're not allowed to use String.concat() or concat Strings with +. I've turned to StringBuilder, but it's mutable.
For instance:
StringBuilder aliasA = new StringBuilder("a");
StringBuilder dot = new StringBuilder(".");
Clausula clause1 = new Clausula(aliasA.append(dot).append("id").toString());
Clausula clause2 = new Clausula(aliasA.append(dot).append("name").toString());
My problem is that when I build clause2
, aliasA is no longer "a"
, but "a.id"
.
PS: I can't use StringBuffer either.