Java String format method

Hello,

I’d like to use the String.format(…) method to format a string like I’d usually do in Java, but it doesn’t seem like it is defined for the String class and I can’t get it to work. Does MicroEJ Java not support this method ? Is there something else I need to import in order to use this method ?

Thank you

Hi harleyj,

Apologies for the delayed reply. Indeed the MicroEJ java.lang.String doesn’t implement the format() method you mentionned, but it is available in the Formatter library available here.
Once you’ve added this library to your project, you can instantiate a Formatter object, with which you can call the format() method to format your string just as you would with String.format(). You can then retrieve your formatted string with the Formatter.toString() method, or even the underlying Appendable object with Formatter.out().

Hope this helps !

Félix