count vs length vs size in a collection

From using a number of programming languages and libraries I have noticed various terms used for the total number of elements in a collection. The most common seem to be length, count, and size. eg. array.length vector.size() collection.count Is there any preferred term to be used? Does it depend on what type of collection it … Read more

Size-limited queue that holds last N elements in Java

A very simple & quick question on Java libraries: is there a ready-made class that implements a Queue with a fixed maximum size – i.e. it always allows addition of elements, but it will silently remove head elements to accomodate space for newly added elements. Of course, it’s trivial to implement it manually: import java.util.LinkedList; … Read more

Kotlin’s List missing “add”, “remove”, Map missing “put”, etc?

In Java we could do the following public class TempClass { List<Integer> myList = null; void doSomething() { myList = new ArrayList<>(); myList.add(10); myList.remove(10); } } But if we rewrite it to Kotlin directly as below class TempClass { var myList: List<Int>? = null fun doSomething() { myList = ArrayList<Int>() myList!!.add(10) myList!!.remove(10) } } I … Read more