Fairly new to Java and have already become quite anoid with the String vs. Stringbuffer delemna. Various sources say use Stringbuffer when you need to re-assign a string variable.
Problem - Stringbuffer class has not even close to the same fuctionality as the String class as far as methods are concerned. For example I have many occasion for the need of Trim and indexOf methods of the String class that aren't in the StringBuffer class.
Sure I can do something like:
BufferedString = BufferedString.toString().trim();
But then not only am I allocating space for a string that will have to be picked up by garbage collection but I am also re-assinging my buffered string. Defeats the purpose of using the BufferedString class. Am I wrong here? And if I'm not is the best solution to write your own methods like trim and indexOf for the BuffereString class?
Problem - Stringbuffer class has not even close to the same fuctionality as the String class as far as methods are concerned. For example I have many occasion for the need of Trim and indexOf methods of the String class that aren't in the StringBuffer class.
Sure I can do something like:
BufferedString = BufferedString.toString().trim();
But then not only am I allocating space for a string that will have to be picked up by garbage collection but I am also re-assinging my buffered string. Defeats the purpose of using the BufferedString class. Am I wrong here? And if I'm not is the best solution to write your own methods like trim and indexOf for the BuffereString class?