Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3320252
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:55:17+00:00 2026-05-17T22:55:17+00:00

Why are listener lists (e.g. in Java those that use addXxxListener() and removeXxxListener() to

  • 0

Why are listener lists (e.g. in Java those that use addXxxListener() and removeXxxListener() to register and unregister listeners) called lists, and usually implemented as Lists? Wouldn’t a Set be a better fit, since in the case of listeners there’s

  • No matter in which order they get called (although there may well be such needs, but they’re special cases; ordinary listener mechanisms make no such guarantees), and
  • No need to register the same listener more than once (whether doing that should result in calling the same listener 1 times or N times, or be an error, is another question)

Is it just a matter of tradition? Sets are some kind of lists under the hood anyway. Are there performance differences? Is iterating through a List faster or slower than iterating through a Set? Does either take more or less memory? The differences are certainly almost negligible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:55:17+00:00Added an answer on May 17, 2026 at 10:55 pm

    One important reason for listener lists to be lists (instead of sets) also explains why you often see them being iterated through backwards. A common scenario involves a listener removing itself as a listener when it’s notified of some change. If the listeners were stored as a list and iterated forward (or stored as a set and iterated in some undetermined order), removing itself as a listener will cause a ConcurrentModificationException.

    So, instead, the listeners are stored as a list and notified in backwards order. Then, if a listener removes itself from the list of listeners when it is notified, it does not cause a ConcurrentModificationException or shift the indices of the other not-yet-notified listeners.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a message listener (using ActiveMQ) that implements SessionAwareMessageListener. When the onMessage(Message,Session) method
What I need: a listener that can accept HTTP messages that contain information in
I have a configuration listener that creates a Hibernate session when a user hits
I created a listener (using netca) called listener. When I start the listener (using
I have a simple Java program that reads in a text file, splits it
I am using WinXP. I use java to generate a list of files. The
Is there a standard interface that can be implemented by beans supporting registration of
I'm writing a Java Tree in which tree nodes could have children that take
I'm trying to implement Observer/Listener pattern with multiple listeners and multiple event types in
I'm encountering a weird issue in Java at the moment that I've never seen

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.