Help in debugging the string concatenation code

Posted by mithun1538 on Stack Overflow See other posts from Stack Overflow or by mithun1538
Published on 2010-04-16T10:50:28Z Indexed on 2010/04/16 10:53 UTC
Read the original article Hit count: 258

I have a code to concatenate strings. However, for some reason, the final string is not a combination of the required strings. Consider the following code :

//cusEmail is of type String[]
String toList = "";
    for(i=0; i < cusEmail.length - 1; i++) {
        toList.concat(cusEmail[i]);
        toList.concat("; ");
        System.out.println(cusEmail[i]);
    }
    toList.concat(cusEmail[i]);
    System.out.println(toList);

The first sout statement displays the strings in cusEmail[i] correctly. However, once concatenated, the second sout displays a blank / empty. Any reason for this? Am i concatenating it correctly?

© Stack Overflow or respective owner

Related posts about concatenation

Related posts about string-concatenation