kotlin setをMutableSetに変換する
kotlinで、setをMutableSetに変換する手順を記述してます。setに対して「toMutableSet」を使用するだけで可能です。
環境
- OS windows11 home
- java 19.0.1
- kotlin 1.7.20-release-201
手順
setをMutableSetに変換するには、「toMutableSet」で可能です。
set名.toMutableSet()
実際に、使用してみます。
fun main() {
var s = setOf("aaa", "bbb", "ccc")
val ms = s.toMutableSet()
ms.add("ddd")
println(ms) // [aaa, bbb, ccc, ddd]
}
変換されていることが確認できます。
-
前の記事
MariaDB 乱数を取得する 2023.12.20
-
次の記事
GAS エラー「GoogleJsonResponseException: API call to people.people.getBatchGet failed with error: Quota exceeded for quota metric ‘Critical read requests (Contact and Profile Reads)’ and limit ‘Critical read requests (Contact and Profile Reads) per minute per user’ of service ‘people.googleapis.com’ for consumer ‘project_number:502114720403’.」が発生した場合の対処法 2023.12.20
コメントを書く