foreachdemo.java

来自「java编程代码」· Java 代码 · 共 36 行

JAVA
36
字号


import java.util.HashSet;
import java.util.Iterator;

public class ForEachDemo
{
    public static void main(String[] args)
    {
        HashSet<String> s = new HashSet<String>( );

        s.add("health");
        s.add("love");
        s.add("money");

        System.out.println("The set contains:");

        String last = null;
        for (String e : s)
        {
           last = e;
           System.out.println(e);
        }

        s.remove(last);

        System.out.println( );
        System.out.println("The set now contains:");

        for (String e : s)
            System.out.println(e);

        System.out.println("End of program.");
    }
}

⌨️ 快捷键说明

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