top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the difference between Collections.emptyList() vs new instance?

+2 votes
91 views
What is the difference between Collections.emptyList() vs new instance?
posted Jun 3, 2015 by Karthick.c

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Both methods return an empty list, but Collections.emptyList() returns a list that is immutable. This mean you cannot add new elements to the "empty" list. At the background, each call of Collections.emptyList() actually won't create a new instance of an empty list. Instead, it will reuse the existing empty instance. If you are familiar Singleton in the design pattern, you should know what I mean. So this will give you better performance if called frequently.

answer Jun 5, 2015 by Shyam
...