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

Unlike many languages, Kotlin distinguishes between mutable and immutable collections (lists, sets, maps, etc). Precise control over exactly when collections can be edited is useful for eliminating bugs, and for designing good APIs. https://kotlinlang.org/docs/reference/collections.html You’ll need to use a MutableList list. class TempClass { var myList: MutableList<Int> = mutableListOf<Int>() fun doSomething() { // myList = … Read more

Check a collection size with JSTL

<c:if test=”${companies.size() > 0}”> </c:if> This syntax works only in EL 2.2 or newer (Servlet 3.0 / JSP 2.2 or newer). If you’re facing a XML parsing error because you’re using JSPX or Facelets instead of JSP, then use gt instead of >. <c:if test=”${companies.size() gt 0}”> </c:if> If you’re actually facing an EL parsing … Read more

Dictionary returning a default value if the key does not exist [duplicate]

TryGetValue will already assign the default value for the type to the dictionary, so you can just use: dictionary.TryGetValue(key, out value); and just ignore the return value. However, that really will just return default(TValue), not some custom default value (nor, more usefully, the result of executing a delegate). There’s nothing more powerful built into the … Read more

How to randomize two ArrayLists in the same fashion?

Use Collections.shuffle() twice, with two Random objects initialized with the same seed: long seed = System.nanoTime(); Collections.shuffle(fileList, new Random(seed)); Collections.shuffle(imgList, new Random(seed)); Using two Random objects with the same seed ensures that both lists will be shuffled in exactly the same way. This allows for two separate collections.

Does List guarantee insertion order?

The List<> class does guarantee ordering – things will be retained in the list in the order you add them, including duplicates, unless you explicitly sort the list. According to MSDN: …List “Represents a strongly typed list of objects that can be accessed by index.” The index values must remain reliable for this to be … Read more

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