Arrays.asList
时间: 2023-09-01 22:13:04 浏览: 108
千万别这样使用Arrays.asList详解
5星 · 资源好评率100%
Arrays.asList() is a method in Java that returns a fixed-size list backed by the specified array. It means that any changes made to the list will also be reflected in the original array. This method is useful when we want to convert an array to a List. For example:
```
String[] arr = {"apple", "banana", "orange"};
List<String> list = Arrays.asList(arr);
```
In this example, the `Arrays.asList()` method is used to convert the `arr` array to a `List<String>` named `list`. Now, any changes made to the `list` will also be reflected in the `arr` array. However, there are some limitations to this method. For example, we cannot add or remove elements from the list as it is a fixed-size list backed by the original array.
阅读全文