知乎专栏 |
package cn.netkiller.apache.lang; import org.apache.commons.lang3.StringEscapeUtils; @SuppressWarnings("deprecation") public class LangTest { public static void main(String[] args) { // TODO Auto-generated method stub String html = "<span>Neo's book</span>"; String encode = StringEscapeUtils.escapeHtml4(html); String decode = StringEscapeUtils.unescapeHtml4(encode); System.out.println(encode); System.out.println(decode); } }
下面例子使用逗号链接字符串
org.apache.commons.lang.StringUtils.join(arraylist, ',')
String project = RandomStringUtils.randomAlphanumeric(10); System.out.print(project);
随机输出 ASCII
System.out.println(RandomStringUtils.randomAscii(10));
随机输出数字
System.out.println(RandomStringUtils.randomNumeric(10));
指定字符串随机输出
String project = RandomStringUtils.random(10, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ").toString(); System.out.println(project);