This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Vectors

 
Chinmay Bajikar
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the difference between how Vector.contains() searches in the vector and how Vector.indexOff() searches in the vector?
Also which one is efficient??
 
Michael Matola
whippersnapper
Ranch Hand
Posts: 1817
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Chinmay Bajikar:
What is the difference between how Vector.contains() searches in the vector and how Vector.indexOff() searches in the vector?
Also which one is efficient??

From the source code of Vector:

You can see that Vector's contains() calls its two-argument indexOf() method. (And the single-argument version of indexOf() also calls the two-argument indexOf().) So they search the same way! Can't imagine that the extra method calls of contains() or single-argument indexOf() have any (measurable) performance impact. I'd base my decision between the two on which return type I need: contains() returns a boolean and indexOf() returns an integer index.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic