How to append a new line to StringBuilder in Kotlin

不问归期 提交于 2020-01-16 09:34:52

问题


In Java, Following code is one way to achieve.

StringBuilder result = new StringBuilder();
result.append(someChar);
result.append("\n");

A better way to do it in kotlin?


回答1:


Kotlin 1.3+ provides Extension Function to ease the task.

Usage:

val strBuilder = StringBuilder();
strBuilder.appendln("some text");


来源:https://stackoverflow.com/questions/57705138/how-to-append-a-new-line-to-stringbuilder-in-kotlin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!