In Java, I am doing this to trim a string:
String input = \" some Thing \";
System.out.println(\"before->>\"+input+\"<<-\");
input = input.trim(
The traditional approach is to use the trim method inline...for example:
String input = " some Thing ";
System.out.println("before->>"+input+"<<-");
System.out.println("after->>"+input.trim()+"<<-");
If it is a string that should be trimmed for all usages, trim it up front like you have done. Re-using the same memory location like you have done is not a bad idea, if you want to communicate your intent to other developers. When writing in Java, memory managment is not they key issue since the "gift" of Java is that you do not need to manage it.