为了获取满足if条件的特定元素,“ pairedDevices”之后的表达式是什么?
//creating a SET of paired devices
val pairedDevices: Set<BluetoothDevice>? = bluetoothAdapter?.bondedDevices
//for each paired device
pairedDevices?.forEach { device ->
if (device.name == "HC-05") {
val hc05 = pairedDevices
}
}
答案 0 :(得分:0)
我认为您正在寻找
hc05 = pairedDevices?.first { it.name == "HC-05" }