Search code examples
javamultithreadingdata-structurespositiondeque

Getting an element from a specific position from a ConcurrentLinkedDeque


How can i get an element from a specific position from a ConcurrentLinkedDeque just like ArrayList.get(index) ?

Thanks and regards,

Rajesh.


Solution

  • ConcurrentLinkedDeque doesn't allow random access. you can only retrieve first or last element.

    though you can iterate over it.

    ConcurrentLinkedDeque<Integer> dq = new ConcurrentLinkedDeque<>();
    Iterator<Integer> itr = dq.iterator();
    while (itr.hasNext()) {
        Integer i = itr.next();
    }
    

    ref: http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentLinkedDeque.html