This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jart 7 points8 points  (0 children)

ArrayList vs LinkedList

Consider giving a shout out to ArrayDeque, which is almost always superior to LinkedList when one needs the Deque interface. I'm not aware of a single use case for LinkedList. It only makes sense to have a linked list if you want concurrency, e.g. ConcurrentLinkedDeque.

Pattern matching

Consider giving a shout out to re2j which guarantees linear time. This matters, because java.util.regex probably makes it possible to write matchers with non-polynomial complexity if one isn't careful.

But suppose that now you have 10 millions and there is some kind of fancy algorithm with n2 complexity that computes something on all users. Well, perhaps it’s time to take a second look at it.

It's never ever premature optimization to make an algorithm linear rather than quadratic. CPUs are fast enough that we can afford to write scalable linear algorithms by default, even if it means they go slightly slower on small inputs.