Kotlin相当于Java的String.getBytes() [英] Kotlin equivalent of Java's String.getBytes()

查看:2351
本文介绍了Kotlin相当于Java的String.getBytes()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In Java, you can convert a string into an array of its constituent bytes by calling myString.getBytes().

在Kotlin中这相当于什么?

What's the equivalent of this in 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相当于Java的String.getBytes()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆