4 ms·
List lacks simple methods to access the head and tail. There are multiple times I wanted to get the tail element but had to do two calls (get size and get(size-
by krzyk 4y ago
List lacks simple methods to access the head and tail. There are multiple times I wanted to get the tail element but had to do two calls (get size and get(size-1)). Having first()/last() methods would make it easy and more readable.
- zasdffaa 4y agoDoesn't java libs have a deq - a double-ended queue?
- jffry 4y agoYes, Java has java.util.Deque [1]. The purpose of this JEP is to add a more generic interface over the ordered collection types, which all have slightly different names for these operations. [1] https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Deque.html https://docs.oracle.com/en/java/javase/17/docs/api/java.base...
- masklinn 4y agoOn the other hand the way the interfaces are layered is not ideal, because the implications of e.g. `removeFirst` and `removeLast` for an arraylist are very different from a linked list. Or getLast on an arraylist (or doubly linked list) versus singly linked.
- yakubin 4y agoNit: "tail" usually means "everything except the head", not "last element". I got a little confused there for a moment reading your comment.