List is an interface, while Vector is a concrete implementation Class. List fixes several minor API deficiencies in Vector. Commonly used Vector operations, such as elementAt and setElementAt, have been given much shorter names.
- We can observe the set method, which replaces the Vector method setElementAt, reverses the order of the arguments so that they match the corresponding array operation.
Example : Consider the following assignment statement.
gift[5] = "golden rings";
The Vector equivalent is:
gift.setElementAt("golden rings", 5);
The List equivalent is:
gift.set(5, "golden rings");
- The method add(int, E), which replaces insertElementAt(Object, int), also reverses the order of the arguments.
- The three range operations in Vector (indexOf, lastIndexOf, and setSize) have been replaced by a single range-view operation (subList), which is far more powerful and consistent.
- We can observe the set method, which replaces the Vector method setElementAt, reverses the order of the arguments so that they match the corresponding array operation.
Example : Consider the following assignment statement.
gift[5] = "golden rings";
The Vector equivalent is:
gift.setElementAt("golden rings", 5);
The List equivalent is:
gift.set(5, "golden rings");
- The method add(int, E), which replaces insertElementAt(Object, int), also reverses the order of the arguments.
- The three range operations in Vector (indexOf, lastIndexOf, and setSize) have been replaced by a single range-view operation (subList), which is far more powerful and consistent.
No comments:
Post a Comment