LinkedList
在添加元素时速度更快。但CCD_ 2在存储数据方面表现较好。
我想我将有100万个元素要添加到列表中。然后我将使用方法saveAll()
将它们保存在DB中。代码如下:
//ArrayList
List<Person> personList = new ArrayList<>();
fullPersonList.forEach(item -> {
if (item.isMale())
personList.add(item);
});
personRepository.saveAll(personList);
//LinkedList
List<Person> personList = new LinkedList<>();
fullPersonList.forEach(item -> {
if (item.isMale())
personList.add(item);
});
personRepository.saveAll(personList);
最好看看personRepository.saveAll(personList)
的定义
无论如何,ArrayList在内部使用一个数组。我预计读取操作会更快,所以我会使用ArrayList
请参阅此处的linked_list_iimplementation