How do I apply the enrich-my-library pattern to Scala collections?

The key to understanding this problem is to realize that there are two different ways to build and work with collections in the collections library. One is the public collections interface with all its nice methods. The other, which is used extensively in creating the collections library, but which are almost never used outside of … Read more

How to add an item to a list in Kotlin?

A more idiomatic approach would be to use MutableList instead of specifically ArrayList. You can declare: val listOfVehicleNames: MutableList<String> = mutableListOf() And add to it that way. Alternatively, you may wish to prefer immutability, and declare it as: var listOfVehicleNames: List<String> = emptyList() And in your completion block, simply reassign it: listOfVehicleNames = response.body()?.message()?.orEmpty() .map … Read more

Finding all objects that have a given property inside a collection [duplicate]

Try the commons collections API: List<Cat> bigList = ….; // master list Collection<Cat> smallList = CollectionUtils.select(bigList, new Predicate() { public boolean evaluate(Object o) { Cat c = (Cat)o; return c.getFavoriteFood().equals(“Wiskas”) && c.getWhateverElse().equals(Something); } }); Of course you don’t have to use an anonymous class every time, you could create implementations of the Predicate interface for … Read more

When is a ConcurrentSkipListSet useful?

ConcurrentSkipListSet and ConcurrentSkipListMap are useful when you need a sorted container that will be accessed by multiple threads. These are essentially the equivalents of TreeMap and TreeSet for concurrent code. The implementation for JDK 6 is based on High Performance Dynamic Lock-Free Hash Tables and List-Based Sets by Maged Michael at IBM, which shows that … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)