public class application {
public void excute(HashMap map){
for(int i=0;i<map.size();i++){
System.out.println(map.get(i+""));
}
}
}
这都定义好了 但我们只实现了返回List数据类型的类
实例代码如下--------------------------------------------------------------
package com.moshi.adapter;
import java.util.ArrayList;
import java.util.List;
public class listserver {
public List getList(){
List list=new ArrayList();
list.add("张三");
list.add("李四");
list.add("王五");
return list;
}
}
public class listadapter extends HashMap{
private List list;
public listadapter(List listserver){
this.list=listserver;
}
public int size(){
return list.size();
}
public Object get(Object i){
return list.get(Integer.valueOf(i.toString()).intValue());
}
}
这个就是适配器的作用。。
然后再在客户端输出
package com.moshi.adapter;
import java.util.List;
import java.util.Scanner;
public class testclient {
public static void main(String[] args) {
application application=new application();
listserver listserver=new listserver();
List list=listserver.getList();
Map listadapter=new listadapter(list);//list->map的适配器
application.excute(listadapter);//输出map型的数据
Scanner scanner=new Scanner(System.in);
double b=scanner.nextDouble();
System.out.print(b);
}