public
synchronized int offsetByCodePoints(int index, int codePointOffset)
Returns
the index within this sequence that is offset from the given index by
codePointOffset code points.
public class StringBufferOffsetByCodepnt { public static void main(String args[]){ int arr1[] = {65536, 65537, 65538, 65539, 65540}; int arr2[] = {65531, 65532, 65533, 65534, 65535}; String s1 = new String(arr1, 0, arr1.length); String s2 = new String(arr2, 0, arr1.length); StringBuffer str1 = new StringBuffer(s1); System.out.println("For str1"); System.out.println(str1.offsetByCodePoints(0, 0)); System.out.println(str1.offsetByCodePoints(0, 1)); System.out.println(str1.offsetByCodePoints(0, 2)); System.out.println(str1.offsetByCodePoints(0, 3)); System.out.println(str1.offsetByCodePoints(0, 4)); StringBuffer str2 = new StringBuffer(s2); System.out.println("For str2"); System.out.println(str2.offsetByCodePoints(0, 0)); System.out.println(str2.offsetByCodePoints(0, 1)); System.out.println(str2.offsetByCodePoints(0, 2)); System.out.println(str2.offsetByCodePoints(0, 3)); System.out.println(str2.offsetByCodePoints(0, 4)); } }
Output
For str1 0 2 4 6 8 For str2 0 1 2 3 4
No comments:
Post a Comment