How can I reverse a Java 8 stream and generate a decrementing IntStream of values?

For the specific question of generating a reverse IntStream, try something like this: static IntStream revRange(int from, int to) { return IntStream.range(from, to) .map(i -> to – i + from – 1); } This avoids boxing and sorting. For the general question of how to reverse a stream of any type, I don’t know of … Read more

What’s the difference between [] and {} vs list() and dict()? [closed]

In terms of speed, it’s no competition for empty lists/dicts: >>> from timeit import timeit >>> timeit(“[]”) 0.040084982867934334 >>> timeit(“list()”) 0.17704233359267718 >>> timeit(“{}”) 0.033620194745424214 >>> timeit(“dict()”) 0.1821558326547077 and for non-empty: >>> timeit(“[1,2,3]”) 0.24316302770330367 >>> timeit(“list((1,2,3))”) 0.44744206316727286 >>> timeit(“list(foo)”, setup=”foo=(1,2,3)”) 0.446036018543964 >>> timeit(“{‘a’:1, ‘b’:2, ‘c’:3}”) 0.20868602015059423 >>> timeit(“dict(a=1, b=2, c=3)”) 0.47635635255323905 >>> timeit(“dict(bar)”, setup=”bar=[(‘a’, 1), (‘b’, … Read more

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

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