Take the 2-minute tour ×

Im trying to append a string that users input into using global keypresses with an api I found. But I can't figure out how to add to the string without overwriting what is already there.

int i = 1;
public String log = "Write";
public String[] logger = new String[i];
public static PrintStream out = null;
public BufferedWriter writer = null;

    public void nativeKeyPressed(NativeKeyEvent e) {

        logger[i] = NativeKeyEvent.getKeyText(e.getKeyCode());
share|improve this question
add comment

1 Answer

Use StringBuilder class append method whenever you have to append characters or string to an existing variable.

StringBuilder strBuilder= new StringBuilder();
strBuilder.append("I am a bad programmer");
strBuilder.append("to use concatenation");
strBuilder.append("Instead of StringBuilder");
strBuilder.append(" or StringBuffer");
String str= strBuilder.toString();

share|improve this answer
That link is not clickable. One has to paste it into the browser's address bar. Therefore I had edited it. –  Lion Feb 5 '13 at 1:00
+1 for using String builder. –  KyelJmD Feb 5 '13 at 1:15
add comment

Your Answer


