Kotlin convert List to vararg

fun foo(vararg strings: String) { /*…*/ } Using foo(strings = arrayOf(“a”, “b”, “c”)) val list: MutableList<String> = listOf(“a”, “b”, “c”) as MutableList<String> foo(strings = list.map { it }.toTypedArray()) Named arguments are not allowed for non-Kotlin functions (*.java) So, in this case you should replace: From: strings = list.map { it }.toTypedArray() To: *list.map { it … Read more

JSTL Sets and Lists – checking if item exists in a Set

You could do this using JSTL tags, but the result is not optimal: <%@ taglib prefix=”c” uri=”http://java.sun.com/jsp/jstl/core”%> <html> <body> <jsp:useBean id=”numbers” class=”java.util.HashSet” scope=”request”> <% numbers.add(“one”); numbers.add(“two”); numbers.add(“three”); %> </jsp:useBean> <c:forEach items=”${numbers}” var=”value”> <c:if test=”${value == ‘two’}”> <c:set var=”found” value=”true” scope=”request” /> </c:if> </c:forEach> ${found} </body> </html> A better way would be to use a custom … Read more

How do I get a list item by index in elm?

Elm added arrays in 0.12.1, and the implementation was massively overhauled in 0.19 to improve correctness and performance. import Array myArray = Array.fromList [1..5] myItem = Array.get 2 myArray Arrays are zero-indexed. Negative indices are not supported currently (bummer, I know). Note that myItem : Maybe Int. Elm does everything it can to avoid runtime … Read more

What’s the difference between List take() vs. getRange() in Dart

The most obvious difference is that take() can only use elements at the beginning, you can combine it with skip() like list.skip(3).take(5) to get similar behavior though. list.take() is lazy evaluated which works nice with functional style programming and might be more efficient if the elements aren’t actually iterated over later. list.take() also is tolerant … Read more

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