Would you help me?
Hi,all:
I notice that many methods of "String" class is non-static,which means each String object has such all methods copies when created.If an application uses many String objects,this design pattern of "String" class will consume much memory.Is this pattern good or bad?
Thank you!
Benjamin
[319 byte] By [
happy_wta] at [2007-9-28 14:59:31]

The methods themselves are not associated with each instance, rather they are associated with the class. The static modifier really indicates the context under which the method may be invoked, not where the method "logic" is held by the JVM.
Thus you should see no memory overhead (on a per-instance basis) as a result of the complexity/number of methods.
The inclusion of local/class variables will have an impact, however, but the extent of this impact will depend on various issues such as scoping, method duration and synchronisation.
I think you've already had this question answered already in this forum, though!
Hope this helps.
As a related note, you do need to be aware of the fact that Java strings are immutable. If you do something like this:
String val = "Hi" + " " + "there" + " " + ",stranger";
You will end up creating a total of 9 Strings. One for each of the actual strings, and then one for each step of the concatenation.
Unless they are doing something different from a compilation perspective nowadays...
Jonathan House