Tag: 阵列

如何在Kotlin中初始化数组?

在Java中,可以初始化一个数组,例如: public static final String[] MONTHS = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; Kotlin的数组初始化是怎样的?

用数组安全地调用Kotlin是令人困惑的

有一个数组: notes: Array<KeyValueNote>? 我在下面的代码中使用Kotlin 1.0.5-2 。 我想要 if (notes != null) { for (note in notes) { // Put the note to the payload Json object only if the note is non-null. payloadJson.put(note.key, note.value) } } 但有几个变化 // Alternative 1. notes?.let { it.takeWhile { it != null /** Inspection will note The condition 'it != […]

如何将字符串数组转换为Int数组在Kotlin?

Kotlin有许多简短而有趣的功能。 所以,我想知道是否有一些快捷方式将字符串数组转换为整型数组。 与Python中的这段代码类似: results = [int(i) for i in results]

如何在Kotlin中初始化一个数组?

在Java中,可以初始化一个数组,例如: int numbers[] = new int[] {10, 20, 30, 40, 50} Kotlin的数组初始化是怎样的?

ByteArray浮在kotlin

我有一个4字节的数组,代表一个浮点值。 由于kotlin缺乏按位操作的字节我怎么能把它转换为最佳的方式浮动?

Kotlin数组初始化函数

我是Kotlin的新手,难以理解init函数如何在Array的上下文中工作。 具体来说,如果我试图使用以下String类型的数组: val a = Array<String>(a_size){"n = $it"} 这工作,但是"n = $it"是什么意思? 这看起来不像init函数,因为它在大括号内而不在括号内。 如果我想要一个Int数组, init函数或者大括号里面的部分是什么样的?

Kotlin中的二维Int数组

在Kotlin中声明指定大小的二维Int数组是否是最简单的方法? val board = Array(n, { IntArray(n) })

索引在Kotlin数组中

我如何从一个Kotlin数组中获得一个值的索引? 我现在最好的解决方案是使用: val max = nums.max() val maxIdx = nums.indices.find({ (i) -> nums[i] == max }) ?: -1 有没有更好的办法?

二维数组在Kotlin

你如何在Kotlin中创建2D Int数组? 我试图将此代码转换为Kotlin: int[][] states = new int[][] { new int[]{-android.R.attr.state_pressed}, // not pressed new int[] { android.R.attr.state_pressed} // pressed }; int[] colors = new int[] { foregroundColor, accentColor, accentColor }; ColorStateList myList = new ColorStateList(states, colors); 这是我尝试过的一个尝试,第一个二维数组没有工作,但我得到了一维数组的工作: //This doesn't work: var states: IntArray = intArrayOf( intArrayOf(-android.R.attr.state_pressed), // not pressed intArrayOf(android.R.attr.state_pressed) // pressed ); //This […]