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

  • SEARCH
  • Home
  • 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 7797061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:33:48+00:00 2026-06-01T23:33:48+00:00

Possible Duplicate: Why does “abcd”.StartsWith(“”) return true? The following simple Java code just uses

  • 0

Possible Duplicate:
Why does “abcd”.StartsWith(“”) return true?

The following simple Java code just uses the startsWith() method.

package startwithdemo;

final public class Main
{    
    public static void main(String[] args)
    {
        System.out.println("My String".startsWith("M"));
        System.out.println("My String".startsWith("My"));
        System.out.println("My String".startsWith(""));
    }
}

It displays true in all the cases. The first two cases are obvious but in the last case (with an empty String), it’s returning true. How?

  • 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-01T23:33:50+00:00Added an answer on June 1, 2026 at 11:33 pm

    Because that’s how the API was designed, see the javadoc.

    But more seriously, one analogy can be to look at sets. Let’s imagine a string is a set of characters, then the empty string is the empty set. In set theory, the empty set is always part of any set.


    Why is the empty set a subset of every set? (taken from here)

    The set A is a subset of the set B if and only if every element of A
    is also an element of B. If A is the empty set then A has no elements
    and so all of its elements (there are none) belong to B no matter what
    set B we are dealing with. That is, the empty set is a subset of every
    set.

    Another way of understanding it is to look at intersections. The
    intersection of two sets is a subset of each of the original sets. So
    if {} is the empty set and A is any set then {} intersect A is {}
    which means {} is a subset of A and {} is a subset of {}.

    You can prove it by contradiction. Let’s say that you have the empty
    set {} and a set A. Based on the definition, {} is a subset of A
    unless there is some element in {} that is not in A. So if {} is not a
    subset of A then there is an element in {}. But {} has no elements and
    hence this is a contradiction, so the set {} must be a subset of A.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Why does “abcd”.StartsWith(“”) return true? Whilst debugging through some code I found
Possible Duplicate: Why does “abcd”.StartsWith(“”) return true? Something similar to this being true caught
Possible Duplicate: C++'s “placement new” in the below code what does Line 3 represents,
Possible Duplicate: g++ “is not a type” error The following does not compile: 1
Possible Duplicate: What does “String[] args” contain in java? I want to know the
Possible Duplicate: Why do C# and Java bother with the “new” operator? Why does
Possible Duplicate: In Ruby what does “=>” mean and how does it work? Just
Possible Duplicate: Why does GetErrorMessage return “wrong password”, when the user name is wrong?
Possible Duplicate: What does “WARN Could not determine content-length of response body.” mean and
Possible Duplicate: What does “$?” give us exactly in a shell script? What does

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.