1. /* 
  2.  * To change this template, choose Tools | Templates 
  3.  * and open the template in the editor. 
  4.  */ 
  5. package sortandcollections; 
  6.  
  7. import java.util.ArrayList; 
  8. import java.util.List; 
  9. import java.util.TreeSet; 
  10.  
  11. /** 
  12.  * 
  13.  * @author Lowitty 
  14.  */ 
  15. public class SortAndCollections { 
  16.  
  17.     /** 
  18.      * @param args the command line arguments 
  19.      */ 
  20.     public static void main(String[] args) { 
  21. //        // TODO code application logic here 
  22. //        char d = 0x0041; 
  23. //        String s3 = "?"; 
  24. //        //Character ch = new Character(); 
  25. //        String s2 = Character.getName(0x1D525); 
  26. //        char[] cs = Character.toChars(0x1000C); 
  27. //        System.out.println(cs); 
  28. //        System.out.println("S2的长度是:" + s3.length() +"\n" + "S2的代码点个数为:" + s3.codePointCount(0, s3.length()) + "\n" + s3); 
  29. //         
  30. //        String s = "asdasgfjaskasvfjasdnasmncvajsldnaskfbak"; 
  31. //        List list = new ArrayList(); 
  32. //        TreeSet ts = new TreeSet(); 
  33. //         
  34. //        //以下为codePoint的测试 
  35. // 
  36. //        int len = 0; 
  37. //         
  38. //        //获取所有的codePoint的长度 
  39. //        int j = s.codePointCount(0, s.length()); 
  40. //        if(j == s.length()){//如果codePoint的个数与字符串s的长度相等的话说明字符串中没有占两个utf-16的特殊字符,则可以把s转为字符数组 
  41. //             
  42. //        } 
  43. //        else{//说明s中含有占位两个utf-16的特殊字符,因此不能简单得将s转为字符串 
  44. //        } 
  45. //         
  46. //         
  47. //        //获取 
  48. //        //int firstCp = s.offsetByCodePoints(0, 0); 
  49. //         
  50. //        /*int cp = s.codePointAt(len); 
  51. //        if(Character.isSupplementaryCodePoint(cp)) 
  52. //            len += 2; 
  53. //        else 
  54. //            len ++; 
  55. //        */ 
  56.          
  57.         //关于代码点相关问题的总结,下面语句声明了一个超出utf-16范围的特殊字符,因此在Java中S的长度为2,但是代码点个数却为1 
  58.         /*String s = "?asdf不咋咋地卡?黛咋珊asd?has咋d?adn?sad"; 
  59.         System.out.println("S为:" + s + "\n" 
  60.                 + "S的长度为:" + s.length() + "\n" 
  61.                 + "S的代码点个数为:" + s.codePointCount(0, s.length()) 
  62.                 ); 
  63.         int x = 0x2A6A5; 
  64.         char [] c = s.toCharArray(); 
  65.         int index = s.offsetByCodePoints(0, 0); 
  66.         int cp = s.codePointAt(index); 
  67.         System.out.println(x + "\n" + cp + "\n" + index); 
  68.         //System.out.println(c[0] + "\n" + c[1]);//无法正常输出*/ 
  69.          
  70.         String s = "?asdf不咋咋地卡?黛咋珊asd?has咋d?adn?sad?"
  71.         int cpCount = s.codePointCount(0, s.length()); 
  72.         int firCodeIndex = s.offsetByCodePoints(00); 
  73.         int lstCodeIndex = s.offsetByCodePoints(0, cpCount - 1); 
  74.          
  75.         System.out.println(firCodeIndex + "\n" + lstCodeIndex + "\n" + cpCount + "\n" + s.length()); 
  76.          
  77.         int counter = 0
  78.         
  79.         for(int index = firCodeIndex ; index <= lstCodeIndex;index += ((Character.isSupplementaryCodePoint(s.codePointAt(index)))?2:1)){ 
  80.             counter ++; 
  81.             System.out.println(counter + "\t"  
  82.                     +index + "\t" 
  83.                     +s.codePointAt(index) +"\t"  
  84.                     + Character.charCount(s.codePointAt(index)) + "\t"  
  85.                     + String.valueOf(Character.toChars(s.codePointAt(index))) + "\t" 
  86.                     + Character.getName(s.codePointAt(index)) + "\t"); 
  87.         } 
  88.          
  89.          
  90.          
  91.         /*String s = "?"; 
  92.         int cp = s.codePointAt(s.offsetByCodePoints(0, 0)); 
  93.          
  94.         //输出的是内存地址 
  95.         System.out.println(Character.toChars(cp) + "\t" 
  96.                 +Character.getName(cp) 
  97.                 ); 
  98.          
  99.         System.out.println(String.valueOf(Character.toChars(cp)) + "\t" 
  100.                 +Character.getName(cp) 
  101.                 ); 
  102.          
  103.          
  104.         //String cs =String.valueOf(Character.toChars(cp)); 
  105.         //System.out.println(cs); 
  106.          
  107.          
  108.          
  109.          
  110.          
  111.          
  112.         for(int index = 0 ; index < cpCount ;){ 
  113.             System.out.println(index + ":" +s.codePointAt(index)); 
  114.         }*/ 
  115.          
  116.          
  117.     }