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 6029627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:54:52+00:00 2026-05-23T04:54:52+00:00

In Java API methods like: String.substring(int beginIndex, int endIndex) String.subSequence(int beginIndex, int endIndex) List.subList(int

  • 0

In Java API methods like:

  • String.substring(int beginIndex, int endIndex)
  • String.subSequence(int beginIndex, int endIndex)
  • List.subList(int fromIndex, int toIndex)

Why is the beginning index inclusive but the end index exclusive? Why shouldn’t they have been designed both inclusive?

  • 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-05-23T04:54:52+00:00Added an answer on May 23, 2026 at 4:54 am

    Because:

    • Java is based on C, and C does it this way
    • It makes the code cleaner: If you want to capture to end of object, pass object.length (however the object implements this, eg size() etc) into the toIndex parameter – no need to add/subtract 1

    For example:

    String lastThree = str.substring(str.length() - 3, str.length());
    

    This way, it is very obvious what is happening in the code (a good thing).

    EDIT An example of a C function that behaves like this is strncat from string.h:

    char *strncat(char *dest, const char *src, size_t n);
    

    The size_t parameter’s value corresponds to the java endPosition parameter in that they are both the length of the object, but counting from 0 if they are the index, it would be one byte beyond the end of the object.

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

Sidebar

Related Questions

I'm using String.format method of Java API to log something. My method is like:
Tried searching in the Java String API with no answer. I am trying to
I am playing with Java's reflection API, and I'm writing methods that inspect a
I'm trying to write a Clojure layer around a Java API that looks like
Many parts of the Java API work differently depending on platform defaults, for example,
I am calling a vendor's Java API, and on some servers it appears that
I'm looking for a Java API to convert ICS (aka iCal) attachments to nicely
I use OpenOffice through the java API, and make him open the .odt file,
I am dealing with a commerical Java API that exposes only the following logging
To recap for those .NET gurus who might not know the Java API: ConcurrentHashMap

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.