- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package sortandcollections;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.TreeSet;
- /**
- *
- * @author Lowitty
- */
- public class SortAndCollections {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // // TODO code application logic here
- // char d = 0x0041;
- // String s3 = "𪚥";
- // //Character ch = new Character();
- // String s2 = Character.getName(0x1D525);
- // char[] cs = Character.toChars(0x1000C);
- // System.out.println(cs);
- // System.out.println("S2的长度是:" + s3.length() +"\n" + "S2的代码点个数为:" + s3.codePointCount(0, s3.length()) + "\n" + s3);
- //
- // String s = "asdasgfjaskasvfjasdnasmncvajsldnaskfbak";
- // List list = new ArrayList();
- // TreeSet ts = new TreeSet();
- //
- // //以下为codePoint的测试
- //
- // int len = 0;
- //
- // //获取所有的codePoint的长度
- // int j = s.codePointCount(0, s.length());
- // if(j == s.length()){//如果codePoint的个数与字符串s的长度相等的话说明字符串中没有占两个utf-16的特殊字符,则可以把s转为字符数组
- //
- // }
- // else{//说明s中含有占位两个utf-16的特殊字符,因此不能简单得将s转为字符串
- // }
- //
- //
- // //获取
- // //int firstCp = s.offsetByCodePoints(0, 0);
- //
- // /*int cp = s.codePointAt(len);
- // if(Character.isSupplementaryCodePoint(cp))
- // len += 2;
- // else
- // len ++;
- // */
- //关于代码点相关问题的总结,下面语句声明了一个超出utf-16范围的特殊字符,因此在Java中S的长度为2,但是代码点个数却为1
- /*String s = "𪚥asdf不咋咋地卡𪚥黛咋珊asd𪚥has咋d𪚥adn𪚥sad";
- System.out.println("S为:" + s + "\n"
- + "S的长度为:" + s.length() + "\n"
- + "S的代码点个数为:" + s.codePointCount(0, s.length())
- );
- int x = 0x2A6A5;
- char [] c = s.toCharArray();
- int index = s.offsetByCodePoints(0, 0);
- int cp = s.codePointAt(index);
- System.out.println(x + "\n" + cp + "\n" + index);
- //System.out.println(c[0] + "\n" + c[1]);//无法正常输出*/
- String s = "𪚥asdf不咋咋地卡𪚥黛咋珊asd𪚥has咋d𪚥adn𪚥sad𪚥";
- int cpCount = s.codePointCount(0, s.length());
- int firCodeIndex = s.offsetByCodePoints(0, 0);
- int lstCodeIndex = s.offsetByCodePoints(0, cpCount - 1);
- System.out.println(firCodeIndex + "\n" + lstCodeIndex + "\n" + cpCount + "\n" + s.length());
- int counter = 0;
- for(int index = firCodeIndex ; index <= lstCodeIndex;index += ((Character.isSupplementaryCodePoint(s.codePointAt(index)))?2:1)){
- counter ++;
- System.out.println(counter + "\t"
- +index + "\t"
- +s.codePointAt(index) +"\t"
- + Character.charCount(s.codePointAt(index)) + "\t"
- + String.valueOf(Character.toChars(s.codePointAt(index))) + "\t"
- + Character.getName(s.codePointAt(index)) + "\t");
- }
- /*String s = "𪚥";
- int cp = s.codePointAt(s.offsetByCodePoints(0, 0));
- //输出的是内存地址
- System.out.println(Character.toChars(cp) + "\t"
- +Character.getName(cp)
- );
- System.out.println(String.valueOf(Character.toChars(cp)) + "\t"
- +Character.getName(cp)
- );
- //String cs =String.valueOf(Character.toChars(cp));
- //System.out.println(cs);
- for(int index = 0 ; index < cpCount ;){
- System.out.println(index + ":" +s.codePointAt(index));
- }*/
- }
- }