如何将数组字符串分配给数组对象

时间:2015-05-21 15:39:50

标签: java

我有这样的事情:

List<Page> result = new ArrayList<Page>();

Page是一个包含3个字符串变量的类;

我有一个数组:

List<String[]> output = new ArrayList<String[]>();

在循环中填充如下:

String[] out = new String[3];   
out[0] = "";
out[1] = "";
out[2] = "";

然后添加到输出:output.set(i, out);

如何将输出 (类型:字符串)分配给结果 (类型:页面)?< / p>

1 个答案:

答案 0 :(得分:2)

我猜你正在寻找这样的东西(代码需要Java 8,但可以使用循环轻松地为早期版本重写)

List<String[]> output = new ArrayList<String[]>();
// populate output with arrays containing three elements 
// which will be used used to initialize Page instances
//...

List<Page> result = output.stream()
                          .map(arr -> new Page(arr[0], arr[1], arr[2]))
                          .collect(Collectors.toList());
相关问题