package namespace;
import java.util.*;
class Student implements Comparable<Student>
{
private String id;
public String name;
public Student(String id,String name)
{
this.id=id;
this.name=name;
}
public String getName()
{
return this.name;
}
public String getId()
{
return this.id;
}
public int hashCode()
{
return this.name.hashCode()+this.id.hashCode();
}
public boolean equals(Object obj)
{
Student student=(Student)obj;
return this.name.equals(student.name) && this.id.equals(student.id);
}
public int compareTo(Student stu)
{
int num=this.id.compareTo(stu.id);
if(num==0)
return this.name.compareTo(stu.name);
return num;
}
public String toString()
{
return id+"..."+name;
}
}
public class ManyMap {
public static void main(String args[])
{
/* 这是一个一对多的映射,就是一个学样对应多个班级,一个班级又对应多个学生
HashMap<String,HashMap<String,String>>nyist=new HashMap<String,HashMap<String,String>>();//定义nyist学校名
HashMap<String,String>jsjx=new HashMap<String,String>();//定义班级名
HashMap<String,String>ysx=new HashMap<String,String>();//定义第二个班级名
nyist.put("jsjx",jsjx);
nyist.put("ysx",ysx);//将班级加到学校里
//下面向班里面加人
jsjx.put("001","boy");
jsjx.put("002","girl");
jsjx.put("003","xiaozhang");
ysx.put("001","xiaoli");
ysx.put("002","hujintao");
ysx.put("003","wenjiabao");
//下面找出jsjs里面的所有的人
HashMap<String,String>classes=nyist.get("jsjx");
Set<Map.Entry<String,String>>entryset=classes.entrySet();
for(Iterator<Map.Entry<String,String>> it=entryset.iterator();it.hasNext();)
{
Map.Entry<String,String> me=it.next();
System.out.println(me.getKey()+"..."+me.getValue());
}
//下面找出nyist 里面所有的人
Set<Map.Entry<String,HashMap<String,String>>>outentry=nyist.entrySet();
for(Iterator<Map.Entry<String,HashMap<String,String>>>it=outentry.iterator();it.hasNext();)
{
Map.Entry<String,HashMap<String,String>> out=it.next();//得到it.next()取得的班级
System.out.println("班级:"+out.getKey());
HashMap<String,String>inner=out.getValue();//得到班级的hashmap
Set<Map.Entry<String,String>>clainner=inner.entrySet();
//System.out.println(clainner);
sop(clainner);
}
}
public static void sop(Set<?>list)
{
for(Iterator<?>it=list.iterator();it.hasNext();)
{
System.out.println(it.next());
}
}*/
//下面不用HashMap<String,String> 来表示学生了,因为在实际开发中,学生要被封装成类,因为定义在Student 类中
HashMap<String,List<Student>>nyist = new HashMap<String,List<Student>>();//定义学校,里面有班级和学生集合的映射,一个班级对应一个学生集合
List<Student>jsjx=new ArrayList<Student>();
List<Student>ysx=new ArrayList<Student>(); //定义两个学生类,也就是两个班级里的人数
nyist.put("jsjx",jsjx);
nyist.put("ysx",ysx);//将两个班级放到学校里面去
jsjx.add(new Student("001","zhangsan"));
jsjx.add(new Student("002","zhaolin"));
ysx.add(new Student("0032","zhau"));
ysx.add(new Student("1230","ahde"));
Set<Map.Entry<String,List<Student>>> entrykey = nyist.entrySet();
for(Iterator<Map.Entry<String,List<Student>>>it=entrykey.iterator();it.hasNext();)
{
Map.Entry<String,List<Student>> item=it.next();
System.out.println("班级:"+item.getKey());
List<Student>stu=item.getValue();
/*for(Iterator<Student>iterator=stu.iterator();it.hasNext();)
{
System.out.println(it.next());
}*/
show(stu);
}
}
public static void show(List<?> list)
{
for(Iterator<?>it=list.iterator();it.hasNext();)
{
System.out.println(it.next());
}
}
}
- 浏览: 618688 次
- 性别:
- 来自: 郑州
最新评论
-
AlanKay:
Mart_dai 写道Hi 齐晓威_518,我想问问,在exc ...
java 后台 Excel 文件生成后转化为字节流 -
18335864773:
国内的pageoffice插件也可以生成excel。也可以用流 ...
java 后台 Excel 文件生成后转化为字节流 -
JAVA_CLASSm:
你好,请问这个还有源码吗?我刚开始接触这个,想要源码学习一下. ...
同一账号不能多地登录(限制同一账号同一时刻只能一个用户登录使用,向QQ一样) -
pangjinquan:
...
前台JS获取后台的Json数据, 动态创建table并填充数据--转自一位朋友 -
lvjun106:
这是增加删除列,,,,
JQuery自动为表格增加一列
相关推荐
public String helloHtml(HashMap<String, Object> map) { map.put("hello", "欢迎进入HTML页面"); return "/index"; } } --------------------------- HelloWorldController --------------------------- ...
ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>(); HashMap<String,String> map1 = new HashMap<String,String>(); HashMap<String,String> map2 = new HashMap<String,String>...
HashMap<String, String> map1 = new HashMap<String, String>(); HashMap<String, String> map2 = new HashMap<String, String>(); HashMap<String, String> map3 = new HashMap<String, String>(); map1.put("name...
Map<String, Object> map = new HashMap<String, Object>(); map.put("ACTID", announcementBean.getActid()); map.put("ACTTITLE", announcementBean.getActtitle()); map.put("ACTCON", announcementBean....
Map<String,Object> map = new HashMap<>(); map.put("name", "山东"); map.put("value", 200); map.put("id", 1); Map<String,Object> map1 = new HashMap<>(); map1.put("name", "江苏"); map1....
Map<String, String> map1 = new HashMap<String, String>(); map1.put("catagory", "三方存管变更"); map1.put("catagoryid", "3411225"); map1.put("seriesdata", "5"); list.add(map1); Map<String, String...
<br><br>}<br><br>或者:<br><br>Map map = new HashMap();<br><br>for (Iterator iter = map.keySet().iterator(); iter.hasNext();) {<br><br> Object key = iter.next();<br><br> Object val = map.get(key);<br>...
Map<String,List<Map<String,String>>> bindMap = new HashMap<String,List<Map<String,String>>>(); List<Map<String,String>> optList = new ArrayList<Map<String,String>>(); for(int j=0;j<operationList....
HashMap<String, Object> jsonMap = new HashMap<>(); jsonMap.put("name", "张三"); jsonMap.put("age", 30); jsonMap.put("isStudent", false); ``` 3. 转换HashMap为JSON 使用Gson库将HashMap转换为JSON字符串: ...
Map<String, Object> parameters = new HashMap<>(); parameters.put("REPORT_DATA_SOURCE", dataSource); // 数据源 JasperPrint jasperPrint = JasperFillManager.fillReport(compiledReportStream, parameters);...
cart = new HashMap<>(); session.setAttribute("cart", cart); } if (cart.containsKey(item.getId())) { item.setQuantity(cart.get(item.getId()).getQuantity() + item.getQuantity()); } cart.put(item....
HashMap<String,Object> maps = new HashMap<String,Object>(); HashMap<String,Object> kvmap = new HashMap<String,Object>(); maps.put("expression", "(((AA*-BB)*CC+(AA*-BB)/CC)+((AA*(-BB))*CC+(AA*-...
Map<String, Object> map = new HashMap<String, Object>(); map.put("serSupplier", "afasfasf"); map.put("callTime", "ffffffffff"); Map<String, WebServiceResultBean> rs = ser.invoke("EOMS", ...
Map<String, Object> itemMap = new HashMap<>(); for (String key : obj.keySet()) { itemMap.put(key, obj.get(key)); } list.add(itemMap); } ``` 以上三种库各有优缺点,Gson和Jackson性能较好,org....
private ArrayList<HashMap<String, Object>> list; // 用来控制CheckBox的选中状况 private ArrayList<Boolean> isSelected; // 上下文 private Context context; // 用来导入布局 private ...
ArrayList<HashMap<String, Object>> list = new ArrayList<>(); HashMap<String, Object> hashMap; try { arr = new JSONArray(jsonString); for (int i = 0; i < arr.length(); i++) { hashMap = new ...
在`JNI处理hashmap.txt`中,你可能会找到关于如何遍历HashMap,添加、删除和查找元素的具体步骤。`JNI对象的操作.txt`可能会涵盖更多基本对象的创建和访问,而`JNI字符串处理.txt`将详细讲解String对象的各种操作。`...
Map<Integer, String> result = new HashMap<>(); for (int i = 0; i < testList.size(); i++) { Map<String, Object> tmp = testList.get(i); result.put((Integer) tmp.get("ID"), (String) tmp.get("NAME"));...
ArrayList<HashMap<String, String>> dataList = new ArrayList<HashMap<String, String>>(); HashMap<String, String> new_data = new HashMap<String, String>(); new_data.put("OBDID", "111111"); new_data....
通过引用【opevcsv】依赖,逐行读取数据 并转为Map<String,Object>格式,后续可以通过BeanUtil.MaptoBean()方法将map转为你需要的bean对象; csv文件必须带表头,bean对象命名符合驼峰格式; 通过此方法可以快速的将...