Sample code for 30+ languages & platforms
Java Requires Chilkat v11.1.0+

HTML Entity Encode and Decode in StringBuilder

Demonstrates HTML encoding and decoding the contents of a StringBuilder.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.StringBuilder;

public class ChilkatExample {

    public static void main(String[] args) {
        StringBuilder sb = new StringBuilder();

        String s = "< é ü ç Ω Hello & World ✓ >";
        sb.append(s);

        sb.encode("html", "utf-8");
        System.out.println(sb.getAsString());

        // Output:
        // < &eacute; &uuml; &ccedil; &ohm; Hello & World &check; >

        // To decode:
        sb.decode("html", "utf-8");
        System.out.println(sb.getAsString());

        // Output:
        // < é ü ç Ω Hello & World ✓ >
    }
}