将字符串转换为字符的迭代器。
//来 自 NowJava.com - 时 代 Java //package com.nowjava; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; public class Main { /** * Converts a string to an iterator of characters. */ public static Iterator<Character> toIterator(final String value) { return new Iterator<Character>() { int index = 0; @Override public boolean hasNext() { return index < value.length(); } @Override/**from 时 代 Java - nowjava.com**/ public Character next() { return value.charAt(index++); } @Override public void remove() { } }; } /** * Wraps a map iterator with an iterator that returns tuples of [key, * value]. */ public static Iterator<?> toIterator(Map<?, ?> o) { final Iterator<?> it = o.entrySet().iterator(); return new Iterator<Object>() { @Override public boolean hasNext() { return it.hasNext(); } @Override public Object next() {