commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim O'Brien <tobr...@discursive.com>
Subject Re: [collections] Name that data structure
Date Tue, 05 Jul 2005 09:06:36 GMT
Tim O'Brien wrote:

> Wendy, you could most certainly use a LRUMap with a fixed size.   Give 
> each item a unique key and let the Map take care of uniqueness.  
> LRUMap will take care of discarding the least recently used entry once 
> it reached the maximum defined size, and the Iterator returns most 
> recently used to least recently used.  This would be the easiest way 
> to do this, by far.

Sorry, hit send too quickly, so that code compared to the LRUMap solution:

        Map map = new LRUMap(5);
       
        map.put( "Page 1", "" );
        map.put( "Page 2", "" );
        map.put( "Page 3", "" );
        map.put( "Page 4", "" );
        map.put( "Page 5", "" );
        map.put( "Page 6", "" );
        map.put( "Page 7", "" );
        map.put( "Page 8", "" );
        map.put( "Page 9", "" );
        map.put( "Page 1", "" );

        Iterator i = map.keySet().iterator();
        while (i.hasNext()) {
            String value = (String) i.next();
            System.out.println(value);
        }





---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message