Search code examples
javavectorsetfinite-automata

vector vs set in java


which one do you prefer?

I want to make a finite automata in java; is it more efficient using vector or set?


Solution

  • A Vector is a class. A Set is an interface. I would use an ArrayList instead of a Vector anyway, if you're not doing something that needs to be threadsafe. Or a standard array if it's not going to get resized.

    It really depends on your application though. Specifically, Sets don't allow duplicate elements, whereas Arrays (Arraylists, Vectors) do.

    Personally I would use an array, unless it needed to have some kind of special functionality (resizing, no duplicate elements, etc.)