CDA數(shù)據(jù)分析
2023-07-26 18:44 作者:tuke007短痛不 | 我要投稿
第三種、適用迭代器Iterator遍歷:直接根據(jù)List集合的自動(dòng)遍歷
import java.util.ArrayList;
public class Demo03 {
public static void main(String[] args) {
ArrayList<News> list = new ArrayList<News>();
list.add(new News(1,"list1","a"));
list.add(new News(2,"list2","b"));
list.add(new News(3,"list3","c"));
list.add(new News(4,"list4","d"));
? ? ?Iterator<News> iter = list.iterator();
? ? ?while (iter.hasNext()) {
? ? ? ? ? ? News s = (News) iter.next();
? ? ? ? ? ? System.out.println(s.getId()+"? "+s.getTitle()+"? "+s.getAuthor());
}
}
}?
---------------------------------------------------------------------------------------------------------
課程獲?。篽ttps://pan.baidu.com/s/1c2PVC4gBd4JjXdKY2KBLTQ?pwd=z5na?
標(biāo)簽: