what is the fastest way of sorting through thousands of objects?
I need to sort through thousands of objects using some sort of identifier, but im not sure what the fastest way is?
Arraylist
List
Map<string, user>?
14 Replies
⌛ This post has been reserved for your question.
Hey @Ferra! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.What do you mean by "sorting through"? Do you need it to be sorted? Do you need to find things based on some key?
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.I have a list of user objects, and I need to be able to get one by user ID string
Use a HashMap then.
well in this case map is fastest
I am using a hashmap, but running through it still takes around 3 minutes
lol wtf
show the code
Well you need to be more specific what you want to do then.
thousands of objects and 3 min to get the key
sounds like somethings wrong with the implementation
trying to search for words that are maybe in around 50ish entries work just fine, but if i search for something thats in the majority, then it takes ages
it doesnt make sense to me since either way it is going through the same amount of map entries
Ok, this is not getting entries by a key. You want to find by search terms and this is a different use case.
First of all you are lowercasing a lot in your search and each lowercase is allocating new strings. An easy improvement might be to just store the lowercase strings in a separate map. That will improve the search time a lot. If you want to scale more though you need to investigate for better string-search-optimized datastructures like radix trees or similar.
can you explain what you wanna do with this code
cuz you are doing a lot of checking with entry and search term
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.