Here you can find the source of htmlSpecialChars(String html)
public static String htmlSpecialChars(String html)
//package com.java2s; //License from project: Open Source License public class Main { public static String htmlSpecialChars(String html) { StringBuilder builder = new StringBuilder(html); for (int index = 0; index < builder.length(); index++) { String toInsert;/*from w w w. j a va 2 s . c om*/ switch (builder.charAt(index)) { case '<': toInsert = "<"; break; case '>': toInsert = ">"; break; case '\'': toInsert = "'"; break; case '"': toInsert = """; break; case '&': toInsert = "&"; break; default: continue; } builder.deleteCharAt(index); builder.insert(index, toInsert); index += toInsert.length() - 1; } return builder.toString(); } public static String insert(String string, int index, char input) { return insert(string, index, input + ""); } public static String insert(String string, int index, String input) { if (index <= 0) return input + string; if (index >= string.length()) return string + input; return string.substring(0, index) + input + string.substring(index); } }