Here’s how to format a message in Java using MessageFormat.
import java.text.MessageFormat; public class Formatter { public static void main(String[] args) { showMessage("Java", "is", "great"); } private static void showMessage(String param1, String param2, String param3) { String message = MessageFormat.format("This message contains 3 parameters. The #1 is ''{0}'', the #2 is ''{1}'', and the #3 is ''{2}''.", param1, param2, param3); System.out.println(message); } }
If you have any questions, leave a comment or ask me on my social media.