// iterating over a String containing some 32-bit Unicode // encoded as surrogate pairs: final int length = str.length(); // Note off does not count characters; // it tracks the offset in the String. // Note no off++ ! for ( int off=0; off<length; ) { int codePoint = str.codePointAt( off ); /* ... */ // hop to next character, normally 1 slot further along. // This incrementer code can't go in the for since codepoint is undefined there. off += Character.charCount( codePoint ); }