android-nuc / 17_Java_Train

17级 Android 实验室 Java 培训
12 stars 2 forks source link

1713011342--许超 #44

Open DreamMemory001 opened 6 years ago

DreamMemory001 commented 6 years ago
import java.util.ArrayList;
import java.util.Iterator;

public class getData {
    public static   void main(String[] args) {
        ArrayList<String> gd = new ArrayList<>();
        gd.add("xiaomei");
        gd.add("jiahao");
        gd.add("xc");
        gd.add("wrf");
        gd.add("chengzhang");
        gd.add("zilong");
        gd.add("huifeng");
        gd.add("yuxin");
        gd.add("xiaoxia");
        gd.add("dingjiang");

        //方法一
        Iterator it = gd.iterator();// 获取迭代器
        while (it.hasNext()) {
            System.out.println(it.next());
        }

        //方法二
        for(Iterator iq = gd.iterator(); iq.hasNext();)
        {
            System.out.println(it.next());
        }

        // 方法三
        for (Object obj:gd
                ) {
            String string = (String )obj;
            System.out.println(string);
            if ( string.equals("xiaoxia"))
            {
                gd.remove(string);
            }
        }
        System.out.println(gd);

        // 方法四

        gd.stream().forEach(p -> System.out.println(gd));
    }
}