黑马程序员技术交流社区
标题:
代码哪里错了
[打印本页]
作者:
袁培育
时间:
2012-4-24 09:31
标题:
代码哪里错了
import java.util.*;
class MapTest5
{
public static void main(String[] args)
{
TreeMap<String,TreeMap<String,String>>tm=new TreeMap<String,TreeMap<String,String>>();
TreeMap<String,String>tm1=new TreeMap<String,String>();
TreeMap<String,String>tm2=new TreeMap<String,String>();
tm.put("yure",tm1);
tm.put("jiuye",tm2);
tm1.put("01","zahgnsan");
tm1.put("02","lisi");
tm2.put("01","wangwu");
tm2.put("02","zhaoliu");
getStudentInfo(tm,"yure");
}
public static void getStudentInfo(TreeMap tm,String room)
{
TreeMap<String,String>tm1=tm.get(room);
Set<String>keySet=tm1.keySet();
Iterator<String>it=keySet.iterator();
while(it.hasNext())
{
String s=it.next();
System.out.println(s+".."+tm1.get(s));
}
}
}
作者:
蒋亮
时间:
2012-4-24 10:13
tm1.put("01","zahgnsan");
tm1.put("02","lisi");
tm2.put("01","wangwu");
tm2.put("02","zhaoliu");
tm.put("yure",tm1);
tm.put("jiuye",tm2);
改成这样试试
作者:
蒋亮
时间:
2012-4-24 10:17
朋友,不好意思,刚说错了,你将这句代码TreeMap<String,String>tm1=tm.get(room)改成TreeMap<String,String>tm1=(TreeMap<String, String>) tm.get(room)就可以了
作者:
黑马-刘昌文
时间:
2012-4-24 10:50
由于你在方法(public static void getStudentInfo(TreeMap tm,String room) )中接收的参数类型TreeMap 没有使用泛型,所以在取的时候必须进行向下类型转换!
TreeMap<String,String>tm1=tm.get(room); 改成 TreeMap<String,String>tm1=(TreeMap<String, String>) tm.get(room);
作者:
姚伟涛
时间:
2012-4-24 11:24
package cn.text;
import java.util.*;
class Foo
{
public static void main(String[] args)
{
TreeMap<String,TreeMap<String,String>>tm=new TreeMap<String,TreeMap<String,String>>();
TreeMap<String,String>tm1=new TreeMap<String,String>();
TreeMap<String,String>tm2=new TreeMap<String,String>();
tm.put("yure",tm1);
tm.put("jiuye",tm2);
tm1.put("01","zahgnsan");
tm1.put("02","lisi");
tm2.put("01","wangwu");
tm2.put("02","zhaoliu");
getStudentInfo(tm,"yure");
}
public static void getStudentInfo(TreeMap tm,String room)
{
TreeMap<String,String>tm1=(TreeMap<String, String>) tm.get(room);
Set<String>keySet=tm1.keySet();
Iterator<String>it=keySet.iterator();
while(it.hasNext())
{
String s=it.next();
System.out.println(s+".."+tm1.get(s));
}
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2