Here you can find the source of htmlEncode(String str)
public static String htmlEncode(String str)
//package com.java2s; //License from project: Open Source License public class Main { public static String htmlEncode(String str) { if (str != null) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (c == '<') { sb.append("<"); } else { sb.append(c);/* ww w . j a v a 2s .c o m*/ } } return sb.toString(); } else { return null; } } public static char charAt(String str, int index) { if (str != null && str.length() > index) { return str.charAt(index); } else { return '\0'; } } }