A simple way to create html tags in Java.
It won't create a tree that you can parse, but it will create the text needed. You see we'll use the StringBuilder class along with the Formatter class to accomplish this. This provides a simple way to format a string without using String.format inside of a sb.append call.
import java.util.Formatter;
import java.util.Locale;
public class LocalMe {
public static void main(String[] args) {
StringBuilder sb = new StringBuilder();
Formatter formatter = new Formatter(sb, Locale.ENGLISH);
formatter.format("<%s>%s</%s>", "greeting", "Hello World", "greeting");
System.out.println(formatter.toString());
}
}
No comments:
Post a Comment