Sample code for 30+ languages & platforms
Java

HTML Entity Encode and Decode in StringBuilder

Demonstrates HTML encoding and decoding the contents of a StringBuilder.

Chilkat Java Downloads

Java
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    CkStringBuilder sb = new CkStringBuilder();

    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 ✓ >
  }
}