1、list.toArray 方法将一个list转换成数组
@RequestMapping("toLogin")
public ModelAndView toLogin() {
List<String> list=new ArrayList<String>();
list.add("王利虎");
list.add("张三");
list.add("李四");
int size=list.size();
String[] array = (String[])list.toArray(new String[size]);
ModelAndView mv = new ModelAndView("/login/login");
mv.addObject("ls",array);
return mv;
}
2、Arrays.asList 方法将一个数组转换成一个列表
@RequestMapping
("toLogin")
public ModelAndView toLogin() {
List<String> list = Arrays.asList("王利虎","张三","李四");
ModelAndView mv = new ModelAndView("/login/login");
mv.addObject("ls",list);
return mv;
}