0

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)?

3
  • 3
    A Page is not a String[]. A String[] is not a Page. Commented May 21, 2015 at 15:41
  • What you're trying to do is not possible. Maybe you could give some context as to what you are trying to accomplish and why you think you need to do this to achieve it. Commented May 21, 2015 at 15:43
  • Can you post the code for your Page class? Commented May 21, 2015 at 16:03

1 Answer 1

2

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());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.