General discussion

Locked

Java: My long strings get corrupted

By superdoum ·
Whenever I concatenate a string to an existing very long string, all accentuated characters are replaced by two odd characters. Does anyone know how to resolve this problem?

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Java: My long strings get corrupted

by PrakashAnthony In reply to Java: My long strings get ...

Could you please pass on the string values and their declarations?
Try using StringBuffer instead of String and use the StringBuffer.append() to concatenate strings.

Collapse -

Java: My long strings get corrupted

by superdoum In reply to Java: My long strings get ...

Poster rated this answer

Collapse -

Java: My long strings get corrupted

by michael In reply to Java: My long strings get ...

Yes, as noted above, you should use a StringBuffer for any "stringy" object whose value can change.

The Java language doesn't create string "variable" as such - it creates individual String objects as needed to hold literal values and returns handle references to them.

Pointers to existing strings with the desired values are assigned if possible at compile time.

But if you assign a series of values to a String object at run time, you're actually generating a potentially great number of separate objects.

So, use StringBuffer! See the following URL in the Java Language Specification on Sun's Web site:

http://java.sun.com/docs/books/jls/first_edition/html/javalang.doc12.html#14461

Collapse -

Java: My long strings get corrupted

by superdoum In reply to Java: My long strings get ...

Poster rated this answer

Collapse -

Java: My long strings get corrupted

by superdoum In reply to Java: My long strings get ...

This question was closed by the author

Back to Web Development Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums