tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: [OT] Help with java Lists
Date Tue, 11 Dec 2007 23:14:13 GMT
Hash: SHA1


You need a collection that is:

David kerber wrote:
> I need to have some kind of list or collection that I can search quickly
> for a specific entry


> and then start stepping through the list item by
> item from that point.


The only implementation that meets those needs is a LinkedHashSet.
Unfortunately, there's no way to start iterating from the middle of this
type of data structure (nor any Set for that matter). Sets do not have
an ordering, but a LinkedHashSet provides an order. On the other hand,
it does not provide a way to ask "where is this item in the set"?

For that, you need a List.

I would recommend building your own data type that contains both a List
(for identifying items by index and performing manual iterating rather
than using an Iterator) and a HashMap or something similar for quick
lookups. Store your object -> list index in the map and the objects
themselves in the list. You can even write your own iterator to start in
the middle of a list once you've identified where to start.

> If it seems like I'll never get reasonable speed this way, I could
> switch to calling all the stores' data from the database at once, making
> the lists huge, but only needing to load them once.  However, this makes
> speed in searching the lists much more of an issue, and I don't know
> which way is going to give me the best overall performance for this
> report generation.

Sounds like a lot of premature optimization to me. Why not just read
what you need from the database each time?

- -chris
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla -


To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message