1、通过Collections.emptyList()创建空集合,调用emptyList()方法提供了相应的泛型支持。添加add和remove时会抛出异常。
2、通过Collections.EMPTY_LIST,兼容性差一点。
3、new ArrayList()太耗性能了
java如何获取一个空集合
最新推荐文章于 2023-04-21 17:12:28 发布
1、通过Collections.emptyList()创建空集合,调用emptyList()方法提供了相应的泛型支持。添加add和remove时会抛出异常。
2、通过Collections.EMPTY_LIST,兼容性差一点。
3、new ArrayList()太耗性能了