1. public int codePointAt(int index)
获取字符串中指定位置的字符的UNICODE值,其值等同于(int)charAt(i)
2. public int codePointBefore(int index)
与codePointAt同,不过是相对位置发生了改变
3. public int codePointCount(int beginIndex,int endIndex)
该方法返回从字符串的beginIndex位置开始到endIndex中共有多少UNICODE字符
4. public int offsetByCodePoints(int index,int codePointOffset)
前面着四个方法都是为UNICODE 4.0实现的,请看这段对之的描述:
16-bit char Ok, it's cheating to vote for two different things when it comes to getting rid of ONE THING in Java. But here goes... Look at the abject pain that is caused by Unicode 4.0 support in Tiger. A char is no longer a character. It is a "code unit in the UTF-16 encoding of Unicode". Some characters have two code units. The API for all this is unbelievably wretched. For example, here is how you get the number of characters in a string: int length = str.codePointCount(0, str.length()); Here is how you get the ith character: int ch = str.codePointAt(str.offsetByCodePoints(0, i)); Or, of course, you can ignore the issue and write code that will work just fine for a year until one of your Far Eastern customers complains, and then you are hosed. To fix this would require courage. char would need to be 32 bit. It would be up to the VM how to store String values, as UTF-32 or UTF-16 or some discriminated union or whatever. To make this workable would require compassion instead of wretched API additions. For starters, why not allow for (int ch : str) to iterate through all characters (not code units) of a string?
5. public boolean contentEquals(CharSequence cs)
判断与字符序列对象的内容是否相等
6. public boolean contains(CharSequence s)
判断字符串是否包含着指定的字符序列对象
7. public String replace(CharSequence target,CharSequence replacement)
把字符串中出现的target替换成replacement
8. public static String format(String format,Object... args)
字符串的格式化处理,跟C语言中的类似,例如
System.out.println(String.format("My Age is %d, My Name is %s", 27, "Winter Lau"));
9. public static String format(Locale l,String format,Object... args)
同上,只是增加一个区域参数,例如
String.format(Locale.FRANCE, "e = %+10.4f", Math.E) 的值是 "e = +2,7183"
关于格式化是JDK1.5新增非常重要的功能之一,同时也是非常复杂的功能,如果能掌握这个特性可以大大的简化和美化你的代码.
心情: 一般