在Java中,可以通过调用myString.getBytes()将字符串转换为其组成字节的array.

这在Kotlin 有什么类似功能?

推荐答案

Use the extension String.toByteArray() - which means you will write myString.toByteArray(). Note it defaults to UTF-8 encoding, but you can override this by providing an additional argument.

Kotlin相关问答推荐

Gradle Jooq配置自定义生成器

Android Jetpack编写androidx.compose.oundation.lazy.grid.Items

如何检测一个值是否是Kotlin中的枚举实例?

在 Kotlin 中定义基于多态函数的泛型函数

CompositionLocal 究竟如何以及何时隐式设置值?

如何使用 Kotlin KClass 属性 simpleName 生成空值

如何创建 Kotlin DSL - DSL 语法 Kotlin

Kotlin:泛型、反射以及类型 T 和 T:Any 之间的区别

Kotlin 中 lambda 表达式中的默认参数

如何使 TextInputEditText 只读?

如何将 kotlin 集合作为 varagrs 传递?

在调用Kotlin数据类中的超类构造函数之前访问函数

Kotlin:子构造函数如何使用其父构造函数的辅助构造函数?

如何解决:将Java类转换为Kotlin后出现error: cannot find symbol class ...?

如何在Kotlin中获得KType?

Kotlin:如何从另一个类访问字段?

用于代码生成的ANTLR工具版本4.7.1与当前运行时版本4.5.3不匹配

以Kotlin为单位的货币数据类型

将 androidx.constraintlayout:constraintlayout lib 更新到 2.0.2 版本后出现崩溃 isRtl () null 引用

Kotlin 对象 vs 伴生对象(companion-object) vs 包作用域(package scoped)方法