⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iteratordemo.java

📁 java编程代码
💻 JAVA
字号:

public class IteratorDemo
{
    public static void main(String[] args)
    {
        LinkedList2 list = new LinkedList2( );
        LinkedList2.List2Iterator i = list.iterator( );

        list.addToStart("shoes");
        list.addToStart("orange juice");
        list.addToStart("coat");

        System.out.println("List contains:");
        i.restart( );
        while(i.hasNext( ))
            System.out.println(i.next( ));
        System.out.println( );

        i.restart( );
        i.next( );
        System.out.println("Will delete the node for " + i.peek( ));
        i.delete( );

        System.out.println("List now contains:");
        i.restart( );
        while(i.hasNext( ))
            System.out.println(i.next( ));
        System.out.println( );

        i.restart( );
        i.next( );
        System.out.println("Will add one node before " + i.peek( ));
        i.addHere("socks");
        System.out.println("List now contains:");
        i.restart( );
        while(i.hasNext( ))
            System.out.println(i.next( ));

        System.out.println( );
        System.out.println("Changing all items to credit card.");
        i.restart( );
        while(i.hasNext( ))
        {
            i.changeHere("credit card");
            i.next( );
        }
        System.out.println( );

        System.out.println("List now contains:");
        i.restart( );
        while(i.hasNext( ))
            System.out.println(i.next( ));
        System.out.println( );
    }
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -