一. Lists工具类
1. transform方法
List<String> result = Lists.transform(studentBeanList, new Function<StudentBean, String>() {
@Override
public String apply(StudentBean studentBean) {
return studentBean.getName();
}
});
List<String> result = Lists.transform(studentBeanList, studentBean -> studentBean.getName());
注意事项:
查看transform的源码,studentBeanListd的改变会影响到result结果。
Lists.transform()方法把studentBeanList和funciton传递给了TransformingRandomAccessList的对象,并且返回该对象
当我们遍历result的时候,调用的是TransformingRandomAccessList中的get()方法,其实是对studentBeanList的操作。
2.Lists.partition方法
List<List<StudentBean>> result = Lists.partition(studentBeanList, 200);
查看源码,返回RandomAccessPartition对象
String工具类
1.String.join
public static void main(String[] args) {
List<String> lists = new ArrayList<>();
lists.add("wy");
lists.add("victor");
lists.add("doctor");
System.out.println(String.join("-", lists));
String[] str = {"1", "2", "3"};
System.out.println(String.join(",", str));
}