Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java data structure that retains order, does not allow duplicates, and allows removal and insertion at start and end

Is there a Java data structure that:

  • does not allow duplicates
  • retains insertion order
  • allows removal and insertion at either the start or end of the collection

There is LinkedHashSet, but it only allows remove(object), add(object) as per Set.

like image 847
BobTurbo Avatar asked Oct 20 '25 15:10

BobTurbo


1 Answers

LinkedHashSet will allow removal of the first element, just do

Iterator iter = linkedHashSet.iterator();
if(iter.next()) {
   iter.remove();
}
like image 167
sbridges Avatar answered Oct 22 '25 05:10

sbridges



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!