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
JavaBot
JavaBot6mo ago
This post has been reserved for your question.
Hey @keplerk! Please use /close or the Close Post button 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.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
dan1st
dan1st6mo ago
What kind of array? Arrays don't have a contains method - do you mean ArrayList?
keplerk
keplerkOP6mo ago
Yeah, array list
dan1st
dan1st6mo ago
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?
keplerk
keplerkOP6mo ago
Plane strings
dan1st
dan1st6mo ago
don't use an ArrayList
keplerk
keplerkOP6mo ago
Any suggestion ?
dan1st
dan1st6mo ago
use a HashSet
keplerk
keplerkOP6mo ago
so i hash what i want to compare against and just use hashset.equals(hashed_word) ?
dan1st
dan1st6mo ago
If you use a HashSet instead of an ArrayList, you can do contains() as before
keplerk
keplerkOP6mo ago
So is HashSet.contains faster than ArrayList.contais ?
dan1st
dan1st6mo ago
The idea of a HashSet is that you can quickly find elements because you don't have to check all elements
keplerk
keplerkOP6mo ago
Interesting i shall look more in deep later, but that's the answer i was looking for. Thanks you very much 😄
JavaBot
JavaBot6mo ago
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.
JavaBot
JavaBot6mo ago
Post Closed
This post has been closed by <@306591040406683649>.

Did you find this page helpful?