Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8624027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:25:27+00:00 2026-06-12T07:25:27+00:00

I read from a programming book about 7-8 years ago that checking string.length ==

  • 0

I read from a programming book about 7-8 years ago that checking string.length == 0 is a faster way to check for empty strings. I’m wondering if that statement still holds true today (or if it has ever been true at all), because I personally think string == "" is more straightforward and more readable. I mostly deal with high-level languages such as .NET and java.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:25:28+00:00Added an answer on June 12, 2026 at 7:25 am

    Usually, string object store their length and therefore getting and comparing the integer is very fast and has less memory access than an equals() where you – in the worst case – have to check the length and loop over the characters.

    Anyway, nowadays the equals() method of a string should also check for the length first and therefore it should be – nearly – the same speed as checking for the length.

    equals part in Java (http://www.docjar.com/html/api/java/lang/String.java.html):

    int n = count;
    if (n == anotherString.count) {...}
    

    equals part in Objective-C (http://www.opensource.apple.com/source/CF/CF-476.15/CFString.c) – NSString is based on CFString:

    if (len1 != __CFStrLength2(str2, contents2)) return false;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

History: I read from one of Knuth's algorithm book that first computers used the
I have read the Core Animation Cook Book and Core Animation Programming Guide from
I'm trying to learn programming by myself, I'm working from a book that has
I'm reading a book about parallel programming an it says that it's not thread
I am new to obj-c programming, I read Kochan's book. here is code from
I'm a erlang newbie. When I read the Socket chapter from Programming Erlang and
New to programming. I wrote a Python code (with help from stackoverflow) to read
I read from some books that Phusion Passenger is the answer to easy Ruby
From what I've read from Herb Sutter and others you would think that volatile
I have a string read from another source such as \b\bfoo\bx. In this case,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.