You have three options:
-
Use a StringBuilder:
StringBuilder zText = new StringBuilder (); void fillString(StringBuilder zText) { zText.append ("foo"); }
-
Create a container class and pass an instance of the container to your method:
public class Container { public String data; } void fillString(Container c) { c.data += "foo"; }
-
Create an array:
new String[] zText = new String[1]; zText[0] = ""; void fillString(String[] zText) { zText[0] += "foo"; }
From a performance point of view, the StringBuilder is usually the best option.