如何将ArrayList转换为ArrayList
ArrayList<Object> list = new ArrayList<Object>();
list.add(999);
list.add("cloud");
list.add(3.55);
System.out.println(list.toString());
使用Java 8,可以做到:
List<Object> list = ...;
List<String> strList = list.stream().map(Object::toString).collect( Collectors.toList() );
使用通配符执行此操作,如下所示
ArrayList<String> strList = (ArrayList<String>)(ArrayList<?>)(list);