I do like the Optional class in Java — it is a long awaited elegant replacement for returning null whenever something isn’t there then relying on if( x != null ) checks or using ?: in the format (x == null) ? “foo” : “bar”. It works great also with the new Java stream classes […]
Posts Tagged: collections
Small Request for Lodash Library: Concatenating JavaScript Array In-place
I started using Lodash a few months ago — it does make some of the mundane JavaScript tasks rather easier to perform, such as processing and traversing arrays and collections, filtering and so on. There is however one thing that I would like them to add, and it is to do with arrays concatenation. (And […]
Collection Sorting — Java vs Groovy
With the introduction of lambdas in Java (not so) recently, some argue that Groovy lost some of its thunder, as closures are now first class citizens in the JDK. However, as I’m about to show, while lambda’s pushed the Java language a great deal forward, Groovy still makes a lot of things incredibly easy (and […]
Parallel : Groovy and Java Streams
This is something that every now and then I have to do: check whether either one or all elements of a collection meet a certain criteria.Β The standard code initially in Java involved a for loop and iterating through the collection explicitly and checking the condition at each step. Then Apache Commons came on with their […]
Java Map and Subtleties of getOrDefault vs computeIfAbsent
I wrote recently about the new niceties in the Map interface that Java 8 brought to light where I’m highlighting in particular 2 new methods: getOrDefault and computeIfAbsent (see my previous post here about it). These provide a cleaner (and as it turns out faster too!) way of retrieving values from a Map instance. However, […]
Convenience Factory Methods for Collections in Java 9
Looking the other day through the JDK Enhancements Proposals (aka “JEP“) I came across JEP-269: “Convenience Factory Methods for Collections”. Oh hello, where have you been all these previous JDK releases? π It seems finally the Java world has woken up to what other JVM languages (and not only!) have been offering for a while: […]
Java 8 Accumulators and Adders
If you’ve been using Java for a while now, then like me, you must have saluted the move quite a while back in JDK 1.5 to introduce the atomic classes (AtomicLong, AtomicBoolean and so on). They were a big step forward, away from the clunkyness of having to create ridiculous bottlenecks in the code for […]
Data Validation inside a List
Felt like sharing this, since there might be some other “dinosaurs” like myself (i.e. slow in their using the Apache Commons Collections) — and those guys might find this useful π Occasionally you find yourself providing components that will be used by various modules in a project, and as such you have to employ strict […]
Neat Trick for Returning an Empty List in Java
I’ve found this post actually burried in my “Drafts” — it’s been there for sometime it seems. I recall writing about it on my mobile WordPress application, so I’m guessing I’ve saved it as draft on the blog with the view to apply the code pretty-printing and forgot about it quite likely π So I […]
Apache Commons Collections
I discovered this recently myself (having not been a big fan of Apache Commons Collections in the past) — and it’s a useful feature if you are dealing with a list of objects that can be compared by more than one property. For instance, consider you have a list of Person’s (see class below) which […]