Reputation: 649
I have something like this :
List<Page> result = new ArrayList<Page>();
Page is a class with 3 string variables;
I have an array as such :
List<String[]> output = new ArrayList<String[]>();
Which is populated like this in a loop:
String[] out = new String[3];
out[0] = "";
out[1] = "";
out[2] = "";
then added to output: output.set(i, out);
How can I assign output (type:String) to result (type:Page)?
Upvotes: 0
Views: 36
Reputation: 124245
I am guessing you are looking for something like this (code requires Java 8 but can be easily rewritten for earlier versions using loop)
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());
Upvotes: 2