Java如何迭代字符串的子集?
package org.nhooo.example.text; import java.text.CharacterIterator; import java.text.StringCharacterIterator; public class IterateSubstringExample { private static final String text = "How razorback-jumping frogs can level six piqued gymnasts"; public static void main(String[] args) { CharacterIterator it = new StringCharacterIterator(text, 4, 27, 5); //在此循环中,我们仅迭代了在 //上面的StringCharacterIterator。它从4的索引中读取 //字符串,最多27个字符。所以只需要以下内容 //字符串“剃刀跳蛙”"razorback-jumping frogs" for (char ch = it.first(); ch != CharacterIterator.DONE; ch = it.next()) { System.out.print(ch); } } }