I have two lists like this:
List<Post> posts = Post.findAll();
List<Comment> comments = Comment.findAll();
I want to combine these two into one list but with two maps so that when this back to client, it would be one array with two objects with names.
For example output on clientside:
Array:[posts:{...}, comments:{...}]
How do I achieve this in java?
I tried to add two list to new array but it is not very efficient because I need to loop over complete array on client side:
List<Post> posts = Post.findAll();
List<Comment> comments = Comment.findAll();
List listFinal = new ArrayList();
listFinal.addAll(posts);
listFinal.addAll(comments);
return listFinal;