0% found this document useful (0 votes)
4 views3 pages

Vector methods in Java

The document outlines various vector methods in Java, categorized into adding, accessing, modifying, removing elements, and other utility functions. It details specific methods such as add, get, set, remove, and size, along with their functionalities. Additionally, it includes legacy methods and capabilities for enumeration and iteration.

Uploaded by

dreamsguider
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Vector methods in Java

The document outlines various vector methods in Java, categorized into adding, accessing, modifying, removing elements, and other utility functions. It details specific methods such as add, get, set, remove, and size, along with their functionalities. Additionally, it includes legacy methods and capabilities for enumeration and iteration.

Uploaded by

dreamsguider
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Vector methods in Java

1. Adding Elements
●​ add(E e) – Appends the specified element to the end.​

●​ add(int index, E element) – Inserts element at the specified position.​

●​ addAll(Collection c) – Appends all elements from another collection.​

●​ addElement(E obj) – Legacy method; similar to add(E e).​

2. Accessing Elements
●​ get(int index) – Returns the element at the specified position.​

●​ elementAt(int index) – Legacy equivalent of get(int index).​

●​ firstElement() – Returns the first element.​

●​ lastElement() – Returns the last element.​

3. Modifying Elements
●​ set(int index, E element) – Replaces the element at a given index.​

●​ setElementAt(E obj, int index) – Legacy equivalent of set().​

●​ insertElementAt(E obj, int index) – Inserts element at specified position.​


4. Removing Elements
●​ remove(int index) – Removes element at the specified index.​

●​ remove(Object o) – Removes the first occurrence of the object.​

●​ removeAll(Collection c) – Removes all elements from a collection.​

●​ removeAllElements() – Removes all elements (legacy method).​

●​ removeElement(Object obj) – Legacy equivalent of remove(Object o).​

●​ removeElementAt(int index) – Legacy equivalent of remove(int index).​

5. Capacity and Size


●​ size() – Returns the number of elements.​

●​ capacity() – Returns the current capacity of the vector.​

●​ ensureCapacity(int minCapacity) – Increases capacity if needed.​

●​ setSize(int newSize) – Changes the size of the vector.​

●​ trimToSize() – Trims the capacity to match the size.​

6. Searching Elements
●​ contains(Object o) – Checks if the vector contains the specified element.​

●​ indexOf(Object o) – Returns the index of the first occurrence.​

●​ lastIndexOf(Object o) – Returns the index of the last occurrence.​


7. Enumeration and Iteration
●​ elements() – Returns an enumeration of the elements (legacy).​

●​ iterator() – Returns an iterator.​

●​ listIterator() – Returns a list iterator.​

8. Utility Methods
●​ isEmpty() – Checks if the vector is empty.​

●​ clear() – Removes all elements.​

●​ clone() – Returns a shallow copy of the vector.​

●​ toArray() – Converts vector to an array.​

●​ equals(Object o) – Compares the vector to another object.​

You might also like