zoukankan      html  css  js  c++  java
  • Kotlin – CharSequence IsNullOrBlank() vs IsNullOrEmpty()

    本文摘自:http://blog.farifam.com/2018/01/28/kotlin-charsequence-isnullorblank-vs-isnullorempty/

    Koltin provide two options to check if a CharSequence or String have a null or empty value, IsNullOrBlank & isNullOrEmpty. What’s the difference? let’s check it by code:

    var data: String? = null
    println(data.isNullOrBlank()?.toString())  // output: true
    println(data.isNullOrEmpty()?.toString())  // output: true

    it return same result. How about enter blank string on it:

    data = ""  
    println(data.isNullOrBlank()?.toString())  //output: true
    println(data.isNullOrEmpty()?.toString())  //output: true

    Hmm, it return same result too.. How about enter it with some text?

    data = "hello"
    println(data.isNullOrBlank()?.toString())  //output: false
    println(data.isNullOrEmpty()?.toString())  //output: false

    Yes, of course they all return “false”. How about enter blank text on it?

    data = " " // this is a text with blank space
    println(data.isNullOrBlank()?.toString())  //true
    println(data.isNullOrEmpty()?.toString())  //false

    Yeah there’s the different..

    Happy coding..

  • 相关阅读:
    程序的链接
    Graphviz 画图的一些总结
    C表达式中的汇编指令
    epoll(2) 源码分析
    epoll(2) 使用及源码分析的引子
    eventfd(2) 结合 select(2) 源码分析
    poll(2) 源码分析
    select 源码分析
    kfifo
    程序的机器级表示:寻址方式、指令及栈的运行机制
  • 原文地址:https://www.cnblogs.com/heweiquan/p/11081518.html
Copyright © 2011-2022 走看看