本文介绍了什么是列表或Java中的ArrayList声明差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是新来的Java。
我想知道的区别是:
I am new to Java.I want to know the difference between:
List< String > list = new ArrayList<>();
和
ArrayList< String > list = new ArrayList<String>();
和
ArrayList< String > list = new ArrayList<>();
感谢
推荐答案
第一种是只因为Java 7的有效的,并且是相当于
The first one is only valid since Java 7, and is the equivalent of
List<String> list = new ArrayList<String>();
这只是更简洁。
相同的第三个,即相当于
Same for the third one, which is equivalent to
ArrayList<String> list = new ArrayList<String>();
和因而严格等同于第二个
and thus strictly equivalent to the second one.
您应该preFER第一位的,在答案中提到的以下问题的原因:
You should prefer the first one, for the reasons mentioned in the answers to the following question: List versus ArrayList
这篇关于什么是列表或Java中的ArrayList声明差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!