True. But the OP has lots of problems. For example, the following does not make sense whether str is
a String or an instance of StringBuilder.

str = str.toString(); //error begin from here
...