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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:58:42+00:00 2026-06-01T04:58:42+00:00

I have a direct buffer holding Integers that are already sorted (i.e. 1,1,3,3,3,3,7,7,….). Most

  • 0

I have a direct buffer holding Integers that are already sorted (i.e. 1,1,3,3,3,3,7,7,….). Most values will occur multiple times. I want to find the first position of values I search for.

  1. Is there a search functionality directly working of buffers
    built-into Java? (couldn’t find anything)
  2. If not, is there any decent library providing such functionality?
  3. If not, what search algorithm would recommend for implementation, given that:

    • I will typically have millions of entries in my buffer
    • Speed is very important
    • It must return the first occurrence of the searched number
    • I’d rather not have it modify the data as I will need the original data afterwards

EDIT: Thanks to all the posters suggesting Arrays.binarySearch(), but, as far as I know, direct buffers do not generally have a backing array. That’s why I was looking for an implementation that directly works on the buffer.

Also, each value can occur up to a thousand times, therefore a linear search after finding a landing point might not be very efficient. The comparator suggestion of dasblinkenlight might work though.

  • 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-01T04:58:43+00:00Added an answer on June 1, 2026 at 4:58 am

    The best approach would be to code your own implementation of Binary Search for the buffers. This approach carefully avoids potential performance hits associated with creating views, copying large arrays etc., and stays compact at the same time.

    The code sample at the link returns the rightmost point; you need to replace > with >= on the nums[guess] > check line to get the leftmost point. This saves you potentially costly backward linear search, or using a “backward” Comparator, which requires wrapping your int into Integer objects.

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

Sidebar

Related Questions

I have an ASP.NET server that I do not have direct access to. How
How do I read an image in C so that I can have direct
Am I correct in thinking that that Python doesn't have a direct equivalent for
I have a memory leak that I have isolated to incorrectly disposed direct byte
I have a C library that wants a temporary buffer for scratch space. I'm
I have an app that uses this library (actually a direct port to D
I have a thread that needs to write data from an in-memory buffer to
I would like to have direct access to the text inside a textbox on
If you create an ASP.NET web file project you have direct access to the
I'm writing an app, and in many situations need to have direct access to

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.