Arraylist 问题 ArrayListName.add(new ArrayListName(......));

Arraylist issue ArrayListName.add(new ArrayListName(.......));

我下载了一个名为 comments 的 ArrayList 文件,我对数组有基本的了解,我知道如果你想向数组中添加一些东西你会做。

comments.add(author, text, rating);

但我看到了别的东西或新东西,无法理解。

comments.add(new Comment(author, text, rating)); <<<< 这对我来说是新的

所以请大佬们他们之间有什么区别,因为我搜索了但没有好处无法理解。

Array 不同于 ArrayList

根据你的问题,我认为你对 arraylist 有意见。有多种创建对象的方法。在您的代码中,它被创建并添加到一行列表中。

    //Create a new comment
    Comment comment = new Comment(author, text, rating);

    //Add comment to comments arraylist
    comments.add(comment)  which is same as

    //Other way to add to list 
    comments.add(new Comment(author, text, rating));