String Memory Internals | Javalobby
String object itself is rather cheap. It's the text it points to that consumes most of the memoryString is just a thin wrapper around char[] to preserve immutabilitynew String("abc") isn't really that expensive as the internal text representation is reused. But still avoid such construct.When String is concatenated from constant values known at compile time, concatenation is done by the compiler, not by the JVMsubstring() is tricky, but most importantly, it is very cheap, both in terms of used memory and run time (constant in both cases)Read full article from String Memory Internals | Javalobby
No comments:
Post a Comment