Duplicate :
|
|
Relates :
|
A DESCRIPTION OF THE REQUEST : To make a version of the String format method, wich today is a static method, as an instance method, without modifing the string itself, just returning a version of it formatted. Imagine you have a label into your application and you want to set it text from a string obtained from a properties file or from a database table. The string use some formatting tags ( %s, %d, etc ), you have to do String model = "This is my Model String using %s"; myLabel.setText( String.format(model, "Fool") ); result: myLabel get the text set to : "This is my Model String using Fool", and model stais unchanged. The code would get cleanner if possible to do something like: myLabel.setText( model.format("Fool") ); result: myLabel get the text set to : "This is my Model String using Fool", and model stais unchanged. JUSTIFICATION : It would be very usefull to print out formatted strings calling the string object itself. Making the code cleaner.