import java.util.ArrayList; public class Hello { public static void main(String[] args) { String s = "我爱JAVA"; System.out.println(s2unicode(s)); } static ArrayList<String> s2unicode(String s) { char[] charArr = s.toCharArray(); ArrayList<String> list = new ArrayList<>(); for (char c : charArr) { String hex = Integer.toHexString(c); String str = "0000" + hex; list.add("\\u" + str.substring(str.length() - 4)); } return list; } }
输出:
标签:编码,JAVA,String,ArrayList,list,char,Unicode,str From: https://www.cnblogs.com/felixwan/p/16717736.html