new ArrayList<>(0)
时间: 2024-04-14 13:29:49 浏览: 20
new arraylist<>(); 表示创建一个新的 ArrayList 对象。ArrayList 是 Java 中的一种集合类型,可以存储一组对象,并且可以动态地增加或删除其中的元素。这里的 <> 表示泛型,可以指定 ArrayList 中存储的元素类型。例如,new ArrayList<String>() 表示创建一个存储字符串类型的 ArrayList 对象。
相关问题
Variable 'maps"initializer ' new Arraylist<>0 is redundant
As an AI language model, I cannot see the whole context of your code, but based on the error message, it seems like you are initializing an ArrayList with an unnecessary argument.
In Java, when you create a new ArrayList, you can either leave it empty or initialize it with elements. The syntax for creating an empty ArrayList is:
```java
ArrayList<Type> listName = new ArrayList<>();
```
In this case, the ArrayList is initialized with no elements.
However, if you want to initialize the ArrayList with elements, you can pass them as arguments, like this:
```java
ArrayList<Type> listName = new ArrayList<>(Arrays.asList(element1, element2, ...));
```
In your case, the error message suggests that you are initializing the ArrayList with an argument of 0, which is redundant because an empty ArrayList is already created with the first syntax. Therefore, you can simply remove the argument and initialize the ArrayList like this:
```java
ArrayList<Type> listName = new ArrayList<>();
```
I hope this helps!
new ArrayList<>是什么意思
在Java中,`new ArrayList<>`是创建一个新的 ArrayList 实例的语法。ArrayList 是 Java 中的一个动态数组类,它实现了 List 接口,提供了一系列操作数组的方法。通过使用`new ArrayList<>`语句,可以创建一个空的 ArrayList 对象,并可以在其中添加、删除和访问元素。方括号中的尖括号`<>`表示泛型,在创建 ArrayList 时可以指定元素的类型。例如,`new ArrayList<Integer>()`创建一个存储整数的 ArrayList 对象。