How to make a Null character in Kotlin

In Java, you can use the escape sequence \0 to represent the Null character

\0 and \0000 are not valid escape sequences in Kotlin, so I used static java char and accessed it from Kotlin.

 public class StringUtils{ public static char escapeChar = '\0'; } 

Is there a letter of the letter Null, or is there a better way to do this in Kotlin?

+7
java kotlin
source share
2 answers

These options will work:

  • '\u0000' (Unicode escape code syntax as described in docs )
  • 0.toChar() ( conversions are optimized and have no service function resources)
  • import java.lang.Character.MIN_VALUE as nullChar , then use nullChar ( import rename )
+20
source share

I believe this should be '\u0000' . For more information, visit the page.

+6
source share

All Articles