Search code examples
javaandroidcharsequence

Combining two CharSequence variables


Can I combine two CharSequence variables like this?

if (status == 1) {
    for (int i = 0; i < get.length(); i++) {
        if (get.charAt(i) == ')') {
        } else {
            temp = temp.toString() + get.charAt(i);     
            // temp and get are charSequence VARIABLES
        }
    }
}         

Syntax is looking OK as no errors from compiler, but the app is crashing.

Also I don't want to get in List and ArrayList items at this beginner stage. Any idea what I am doing wrong?

Also if you say that I shouldn't use .toString() method then I understand but what should I do then to make it correct?


Solution

  • are you sure get is not null ?

    i tried your code and it's working.

    debug and provide values for which your app is crashing.

    and you can achieve the same result with :

    temp = temp.toString() + get.toString().replaceAll("\\)", "");