'How can I include a simple array in List.of()?

I am having a lot of trouble with putting an array as a parameter in one of my REST API methods. My server will be retrieving data from a separate API which requires all the below fields to be set.

public class Article {
    private String by;
    private int descendants;
    private int[] kids;
    private int id;
    private int score;
    private int time;
    private String title;
    private String type;
    private String url;

In another class, I have the following method:

    @Override
    public List<Article> selectAllArticles() {
        //TODO: argument fix needed
        return List.of(new Article("by", "descendants", [???], "id", "score", "title", "type", "url"));
    }

The [???] is where I'm trying to figure out how to write out the array.



Solution 1:[1]

Instead of an int[] array for the kids property, you can use ArrayList so that initialization with size won't be an issue.

Or

If the kid property is just for only mentioning the number of kids then an array is not needed; just int would do.

Also, if only one article is going to be sent, then you can send the article itself instead of packing it in a list.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Peter Mortensen