Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

SessionListener online users - Splitting up lists

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I'm using a SessionListener to check if a user is online or not.
It basically keeps a List of all online users.
Too check if one is online or not I use "contains()".

If there were say a few 1000 users online it would take a while to perform "contains()".
That's why I thought of splitting up the lists in a few lists identified by the first 3 chars or so of the users id.


Is this the way to go, or are there other, better ways of doing this?

Tnx
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The obvious choice for a collection is to use a implementation of the Set interface, for example HashSet - essentially a Map where the entry (user name) is both value and key.

This sort of lookup uses a Hashcode and is very very fast compared to brute force lookups with (for example) an ArrayList.

Bill

 
reply
    Bookmark Topic Watch Topic
  • New Topic