ARTICLE DETAIL

建站实战干货

来自一线的建站与推广经验沉淀,每一条都经过真实交付验证。

设计模式:迭代器模式(Iterator Pattern)

2026/9/12 1:21:55 拓冰建站 浏览量
设计模式:迭代器模式(Iterator Pattern) /** * 迭代器模式。 * author Bright Lee */ public class IteratorPattern { public static void main(String[] args) { String[] strings new String[] { 红烧肉, 鱼香肉丝, 毛血旺 }; IteratorString it new StringIterator(strings); while (it.hasNext()) { String string it.next(); System.out.println(string); } } } /** * 迭代器接口。 */ interface IteratorT { public boolean hasNext(); public T next(); } /** * 迭代器。 */ class StringIterator implements IteratorString { private int index; private String[] strings; public StringIterator(String[] strings) { this.strings strings; this.index 0; } public boolean hasNext() { if (index strings.length) { return false; } return true; } public String next() { String string strings[index]; index; return string; } }运行结果红烧肉鱼香肉丝毛血旺以下是我们工作室开发的软件《榴芒客服系统》的介绍博客里面有软件的下载地址https://blog.csdn.net/look4liming/article/details/164755808