Is there any java Deque that implements maxlen, like python collections.deque? -


python's collections.deque has maxlen argument, such that

[...] deque bounded specified maximum length. once bounded length deque full, when new items added, corresponding number of items discarded opposite end. [...]

i have been looking class implements deque interface in java, same.

public arraydeque(int numelements) looks numelements initializes deque size, doesn't enforce max length.

probably not. linkedhashmap has facilities build cache eviction policies, might overkill want. extend deque , add custom logic ;-)


edit:

class myfixedsizedeque<t> extends arraydeque<t> {    private int maxsize;    public mydeque(int size)    {       this.maxsize = size;     }     @override    public void addlast(t e)    {       this.addlast(e);       if(this.size() > maxsize)          this.removefirst();    }  } 

my java little rusty, , might want overload few more methods (or switch composition rather inheritance) hope idea...


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -