Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.HashMap; import java.util.Map; public class Main { private static Map<Integer, String> entities = new HashMap<>(); public static String encodeEntity(int entity) { if (entities.containsKey(entity)) return entities.get(entity); if (entity < 128) return Character.toString((char) entity); if (entity < 10000) return "&#" + entity + ";"; else return "&#x" + Integer.toHexString(entity) + ";"; } }