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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:41:23+00:00 2026-05-27T07:41:23+00:00

I can’t see any drawbacks in making String.indexOf part of the interface CharSequence .

  • 0

I can’t see any drawbacks in making String.indexOf part of the interface CharSequence. The benefit would be that other classes like StringBuffer or StringBuilder would need to implement the indexOf methods too.

So is there any design reason why indexOf should only be part of String?

Thank you.

  • 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-27T07:41:24+00:00Added an answer on May 27, 2026 at 7:41 am

    I am not sure what is the reason for this but I can give an example of class that implements CharSequence. It is java.nio.CharBuffer.

    Theoretically it could implement indexOf() by calling charAt() in loop. But it will not work as user expects. We cannot distinguish between 2 situations: character is not there yet and character is not there and will not be there. In second case indexOf() should return -1 by contract. In first case it should wait until all bytes arrive. But CharBuffer belongs to non-blocking IO, so it cannot block.

    I believe this explains at least one of the possible reasons.

    EDIT:

    Following very valuable comment by @Pacerier I want to add the following.
    IMHO CharSequence as a very generic interface that is used in different circumstances. The most well known implementors of this interface are String, StringBuffer and StringBuilder that hold the whole content in data structure that allows direct access to any character. This is wrong however in general case. java.nio.CharBuffer is an example of such case.

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

Sidebar

Related Questions

Can't get Youtube's homepage, or any other youtube.com prefixed URL to load in an
Can you specify that it must do one or the other?
can any one tell me how can change this java code into objective c.is
Can the Application Name passed to SQL Server (via the ADO Connection string) be
Can multiple objects be linked (bound) to one name in RMI ? If that
I've got a string that has curly quotes in it. I'd like to replace
Can anybody tell what is the best(easy) way to sort the following string 'index'
Can I set a maximum fps? Is there any way to limit fps in
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Can anyone help me with an excel formula that groups related rows and creates

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.