LinkedList
is faster in add element. But ArrayList
is better in stored data.
I suppose that I will have 1 million elements to add to the List. Then I will use method saveAll()
to save them in DB. Code like below:
//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);