Arrays.asList 如何返回实例化的列表? [英] How can Arrays.asList return an instantiated List?

查看:30
本文介绍了Arrays.asList 如何返回实例化的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Arrays.asList 返回一个类型化的列表.但是 List 是一个接口,那么如何实例化呢?如果尝试实例化类型化列表,我会收到一条错误消息,指出这是不可能的.

Arrays.asList returns a typed List. But List is an interface so how can it be instantiated? If try and instantiated a typed List I get an error saying it is not possible.

编辑

没关系我知道发生了什么,只是被文档弄糊涂了一会儿.

Nevermind I see what's going on, just got confused by the docs for a moment.

推荐答案

它是一个 Arrays.ArrayList,不应与 java.util.ArrayList 混淆.它是数组的包装器,这意味着您所做的任何更改、更改原始数组,并且您不能添加或删除条目.经常与 ArrayList 结合使用,如

It's an Arrays.ArrayList which shouldn't be confused with java.util.ArrayList. It is a wrapper for the array which means any changes you make, alter the original array, and you can't add or remove entries. Often it is used in combination with ArrayList like

 List<String> words = new ArrayList<>(Arrays.asList("Hello", "There", "World"));

这篇关于Arrays.asList 如何返回实例化的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆