Reputation: 1759
If i need an empty list, I could use
Arrays.asList()
or
Collections.emptyList()
What is the difference between these two calls? Which one should I use?
Upvotes: 9
Views: 16370
Reputation: 45005
Collections.emptyList()
is your best option because it reuses an object instead of creating a new object as it will be the case with Arrays.asList()
.
NB: Collections.emptyList()
returns an immutable object so if you intend to modify it later in your code you will need to create your list explicitly instead because you will face the same issue with Arrays.asList()
as it is immutable too.
Upvotes: 9