List转化为List
import lombok.Data;
import java.util.*;
public class testUtil {
@Data
public static class Test {
private String name;
}
public static void main(String[] args){
List<String> A = new ArrayList<>();
A.add("A");
A.add("B");
A.add("D");
List<Test> Z = new ArrayList<>();
for(int i=0;i<A.size();i++)
{
Test test = new Test();
test.setName(A.get(i));
Z.add(test);
}
System.out.println(Z);
}
}
List 转换为 List
import lombok.Data;
import java.util.*;
public class testUtil {
@Data
public static class Test {
private String name;
}
public static void main(String[] args){
List<Test> z = new ArrayList<>();
Test A = new Test();
Test B = new Test();
A.setName("111");
B.setName("222");
z.add(A);
z.add(B);
System.out.println(z);
List<String> collect = z.stream().map(x -> x.getName()).collect(Collectors.toList());
System.out.println(collect);
}
}