java集合框架(习题与答案)资料

map.put(\意大利\

map.put(\南非\

if(map.containsKey(year)){

System.out.println(map.get(year));

}

else{

System.out.println(\这一年没有承办世界杯!\

}

} }

12. (Map)已知某学校的教学课程内容安排如下: 集合框架(习题)\o:button=\target=\href=\mg.cn/orignal/714a8371t9dbaa80ef64e\集合框架(习题)\src=\>

完成下列要求:

1) 使用一个Map,以老师的名字作为键,以老师教授的课程名作为值,表示上述 课程安排。

2) 增加了一位新老师Allen 教JDBC 3) Lucy 改为教CoreJava

4) 遍历Map,输出所有的老师及老师教授的课程 5) *利用Map,输出所有教JSP 的老师。

public static void main(String[] args) {

// TODO Auto-generated method stub

Map map=new TreeMap();

map.put(\

map.put(\

map.put(\

map.put(\

map.put(\

map.put(\

map.put(\

System.out.println(map.size());

map.put(\

System.out.println(map.size());

map.remove(\

map.put(\

Set set=map.keySet();

for(Object obj:set){

System.out.println(map.get((String)obj));

}

for(String str:set){

if(map.get(str).equals(\

System.out.println(\教JSP的老师有:\

}

}

}

13. (泛型)使用泛型,改写第5 题

package list;

import java.util.Iterator;

import java.util.LinkedList;

public class Test2 {

public static void main(String[] args) {

// TODO Auto-generated method stub

LinkedList ll=new LinkedList();

Worker1 w1=new Worker1(\

Worker1 w2=new Worker1(\

Worker1 w3=new Worker1(\

ll.add(w1);

ll.add(w2);

ll.add(w3);

ll.add(1, new Worker1(\

ll.remove(w3);

//用for循环遍历

for(int i=0;i

System.out.println(ll.get(i));

}

System.out.println(\

//用迭代器遍历

Iterator iterator=ll.iterator();

while(iterator.hasNext()){

System.out.println(iterator.next());

}

} }

class Worker1 {

private int age;

private String name;

private double salary;

public Worker1 (){}

public Worker1 (String name, int age, double salary){

this.name = name;

this.age = age;

this.salary = salary;

}

public int getAge() {

return age;

}

public void setAge(int age) {

this.age = age;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public double getSalary(){

return salary;

}

public void setSalary(double salary){

this.salary = salary;

}

public void work(){

System.out.println(name + \

}

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4