Find element in array of 80k elements
Hi,
I have an array of at least 80k elements (don't ask why i use katalon studio and it handles things very bad being just a copy of eclipse)
And i need to look for values within the array, i think using .contains will be veery resource costly.
Is there a proper way to do so ?
Regards.
15 Replies
⌛ This post has been reserved for your question.
Hey @keplerk! 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.
What kind of array?
Arrays don't have a contains method - do you mean
ArrayList?Yeah, array list
ArrayList#contains() needs to call the equals() method with every element until it is found
If you want more efficient contains checks, you should probably use a HashSet and properly implement equals()/hashCode
What are the eleemnts in your list?Plane strings
don't use an
ArrayListAny suggestion ?
use a
HashSetso i hash what i want to compare against and just use hashset.equals(hashed_word) ?
If you use a
HashSet instead of an ArrayList, you can do contains() as beforeSo is HashSet.contains faster than ArrayList.contais ?
The idea of a
HashSet is that you can quickly find elements
because you don't have to check all elementsInteresting i shall look more in deep later, but that's the answer i was looking for.
Thanks you very much 😄
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
Post Closed
This post has been closed by <@306591040406683649>.