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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:14:18+00:00 2026-06-04T07:14:18+00:00

Is there any class in Java, which holds an array of elements both in

  • 0

Is there any class in Java, which holds an array of elements both in order and optimized for fast searching?

I.e. I need to retrieve elements both by numeric index (like in Vector) and by hash (like in HashMap).

LinkedHashMap does not match

I think LinkedHashMap does not match since it guarantees order, but does not allow fast accessing by index (position number). According to description, it will require to traverse entire chain to find a given position. This is what any Collection can with iterator.

EDIT 2

I.e. both searching by key and by index should be fast, not only by key.

  • 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-04T07:14:19+00:00Added an answer on June 4, 2026 at 7:14 am

    You can use a Map for fast retrieval of elements by hash. By definition, a Map is unordered and talking about indexes doesn’t make much sense. Using a LinkedHashMap might be of use, since it guarantees that insertion order is preserved at iteration time, although accessing an element by index will still need some extra processing, something like this:

    map.entrySet().toArray()[index] // mind the casts, etc.
    

    If your map changes infrequently, the above will work nicely if you cache the array and check to see if the size of the map has changed before accessing an entry by index, creating a new array only when a change in size has been detected. On the other hand, if the map changes frequently you’d need to re-create the array at each access, creating a poorly performing data structure.

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

Sidebar

Related Questions

Is there any Java function or util class which does rounding this way: func(3/2)
I'd like to know if there is any class in Java able to check,
Is there any sense to declare default constructor in Java? class MyClass { public
In Java, is there any way to create an instance of any class that
I'm just wondering if there are any Java class editors that work on a
Possible Duplicate: Java Generics: Array containing generics I have a Java class which contains
I have a java class that uses complex static fields which need special operations
Are there any annotations in java which mark a method as unsupported? E.g. Let's
Is there any way to access the Windows Event Log from a java class.
Are there any dictionary classes in the .NET base class library which allow duplicate

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.