Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

785
Views
What is different between isEmpty and isBlank in kotlin

I want to check the value of a String in my in Android project. I saw two functions to check my String value:

item.isBlank()

and

item.isEmpty()

What is difference between them?

over 4 years ago · Hanz Gallego
2 answers
Answer question

0

item.isEmpty() checks only the length of the the string

item.isBlank() checks the length and that all the chars are whitespaces

That means that

  • " ".isEmpty() should returns false
  • " ".isBlank() should returns true

From the doc of isBlank

Returns true if this string is empty or consists solely of whitespace characters.

over 4 years ago · Hanz Gallego Report

0

In future, you can read documentation and see the code from IDE just click Ctrl+B or Command+B. This is written in documantation for isEmpty method:

/**
 * Returns `true` if this char sequence is empty (contains no characters).
 *
 * @sample samples.text.Strings.stringIsEmpty
 */
@kotlin.internal.InlineOnly
public inline fun CharSequence.isEmpty(): Boolean = length == 0

And for isBlank:

 * Returns `true` if this string is empty or consists solely of whitespace characters.
 *
 * @sample samples.text.Strings.stringIsBlank
 */
public actual fun CharSequence.isBlank(): Boolean = length == 0 || indices.all { this[it].isWhitespace() }
over 4 years ago · Hanz Gallego Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!