帮忙看看集合的问题
下面是关于新闻发布系统运用到List+Map+oop技术的程序,2. 实现新闻发布系统中的 n个类别对应 该类别新闻的数据结构并输出 所有类别以及该类别下的所有新闻, 实现添加,修改,删除,查询的功能。程序如下:
第一个类:
package News;
public class Kind {
private String newsKind;
public Kind(String newsKind){
this.newsKind=newsKind;
}
public String getNewsKind() {
return newsKind;
}
public void setNewsKind(String newsKind) {
this.newsKind = newsKind;
}
}
第二个类:
package News;
import java.util.Date;
public class News {
private String theme;
private Date date;
private String place;
private int viewNum;
public News(String theme,Date date,String place,int viewNum) {
this.theme=theme;
this.date=date;
this.place=place;
this.viewNum=viewNum;
}
public String getTheme() {
return theme;
}
public void setTheme(String theme) {
this.theme = theme;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public String getPlace() {
return place;
}
public void setPlace(String place) {
this.place = place;
}
public int getViewNum() {
return viewNum;
}
public void setViewNum(int viewNum) {
this.viewNum = viewNum;
}
}
第三个类:
package News;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
public class NewsDemo1 {
public static void main(String[] args) throws Exception {
//创建新闻对象
Date date =new Date();
News new1=new News("广东一老人买排骨没付款被超市扣留罚700",date, "广东", 3427);
News new2=new News("特朗普首场新闻发布会推迟",date, "美国", 111223);
News new3=new News("中关村二小最新回应",date, "美国", 2235878);
News new4=new News("2017版的三星A7/A5/A3重点规格参数曝光",date, "韩国", 34567);
News new5=new News("朝韩虚拟战争已打响",date, "韩国", 239254);
News new6=new News("厉以宁:中国正发生新人口红利 红利来自农村",date, "中国", 22343);
News new7=new News("揭秘韩国网络代购黑幕:假货只卖给中国人",date, "韩国", 36055);
//创建新闻类型
Kind politic=new Kind("时事政治"); //
Kind dailyNews=new Kind("民生");
Kind army=new Kind("军事");
Kind internet=new Kind("互联网");
//用hashMap组装新闻对象与新闻类型
HashMap<Kind, News> hashMap1=new HashMap<Kind, News>();
HashMap<Kind, News> hashMap2=new HashMap<Kind, News>();
HashMap<Kind, News> hashMap3=new HashMap<Kind, News>();
HashMap<Kind, News> hashMap4=new HashMap<Kind, News>();
HashMap<Kind, News> hashMap5=new HashMap<Kind, News>();
HashMap<Kind, News> hashMap6=new HashMap<Kind, News>();
HashMap<Kind, News> hashMap7=new HashMap<Kind, News>();
hashMap1.put(dailyNews, new1);
hashMap2.put(politic, new2);
hashMap3.put(dailyNews, new3);
hashMap4.put(internet, new4);
hashMap5.put(army, new5);
hashMap6.put(dailyNews, new6);
hashMap7.put(internet, new7);
//用arraylist装填hashMap
ArrayList<HashMap<Kind, News>> list=new ArrayList<HashMap<Kind, News>>();
list.add(hashMap1);
list.add(hashMap2);
list.add(hashMap3);
list.add(hashMap4);
list.add(hashMap5);
list.add(hashMap6);
list.add(hashMap7);
//用Iterator遍历所有对象
Iterator iterator= list.iterator();
while(iterator.hasNext()){ //使用hasNext()检查序列中是否还有元素
HashMap<Kind, News> hashMap= (HashMap<Kind, News>) iterator.next();
Iterator iterator2= hashMap.entrySet().iterator();
while (iterator2.hasNext()) {
Map.Entry entry=(Entry)iterator2.next();
Kind key=(Kind) entry.getKey();
News value=(News) entry.getValue();
System.out.println("今天的新闻有以下内容:"+key.getNewsKind()+" 新闻的主题为"+value.getTheme()+" 事件发生的地点为"+value.getPlace()+" 发生日期为"+value.getDate()+" 评论量为"+value.getViewNum()+" 条");
}
}
}
}
请问下面每一句代表什么意思?
while(iterator.hasNext()){ //使用hasNext()检查序列中是否还有元素
HashMap<Kind, News> hashMap= (HashMap<Kind, News>) iterator.next();
Iterator iterator2= hashMap.entrySet().iterator();
while (iterator2.hasNext()) {
Map.Entry entry=(Entry)iterator2.next();
Kind key=(Kind) entry.getKey();
News value=(News) entry.getValue();
为什么要循环2次?已经创建了iterator为什么还要创建iterator2,特别是第2、5、6句看不明白,请高手指点,谢谢