Passing strings around

I’m making kinda custom simple object language (Almost like XML, but it is mainly for writing UI, so I will not need any ‘special’ character handling and stuff).

I’m starting to write the parser, and I don’t know if I should pass the input string around methods. Does passing string around methods copy it? So for example if I pass string A from method B to method C, does string A stay as it is, or does it get copied and become a new string?

Does passing any object type copy it?

No.

Note however that Java is pass-by-value: http://stackoverflow.com/questions/40480/is-java-pass-by-reference-or-pass-by-value
Just not the way that might be immediately obvious.

Well I just thought that strings might have some magical properties like int or boolean or any other primitive. Ow well.

They can have the interesting properties of being interned and/or de-duplicated. Look up “string interning” or deduplication for more.
Also note that they are immutable, so “modifying” a string is creating a new string. Except that substring used to create a “view” string. It does not anymore though.

For more info: http://java-performance.info/changes-to-string-java-1-7-0_06/

Why don’t you just write a little example program that tests this out?

[quote=“trollwarrior1,post:1,topic:51621”]
Strings aren’t primitives. They are immutable Objects.