Comp Sci Java indexOf() Method: Finding Elements in a Set

  • Thread starter Thread starter 0rthodontist
  • Start date Start date
  • Tags Tags
    Java Method
AI Thread Summary
In Java, the indexOf() method in Vector can check for the presence of an element in a collection but is criticized for its slow performance. TreeSet can efficiently test for element existence but does not return the actual object. The user requires a collection that can both verify element presence and retrieve the object, while also allowing for frequent additions of tens of thousands of elements. There is a concern that the Java API may not provide a suitable solution for these specific needs. The user is seeking alternative APIs that could fulfill these requirements without needing to implement a custom solution.
0rthodontist
Science Advisor
Messages
1,229
Reaction score
0
In Java, I am looking for a collection that will test if a given element is in a set, using the equal() method defined for the element. If it is in the set, I need the collection to give me the actual occurrence of the object from the set. Vector will do this for me via the indexOf() method, but the problem is that the search function in Vector is too slow. TreeSet will do the test for elementhood but won't retrieve the object. I also need to add additional objects to this set fairly regularly (a few tens of thousands of objects). I don't think the Java API has anything that does exactly what I want, but maybe there is another API that does? I'd rather not implement it myself.
 
Last edited:

Similar threads

Replies
2
Views
1K
Replies
5
Views
2K
Replies
4
Views
2K
Replies
1
Views
1K
Replies
2
Views
4K
Replies
12
Views
2K
Replies
5
Views
3K
Replies
1
Views
2K
Replies
1
Views
2K
Back
Top