Replacing Element in Java Vector Last Updated : 11 Dec, 2020 Comments Improve Suggest changes Like Article Like Report To replace an element in Java Vector, set() method of java.util.Vector class can be used. The set() method takes two parameters-the indexes of the element which has to be replaced and the new element. The index of a Vector is zero-based. So, to replace the first element, 0 should be the index passed as parameter. Declaration: public Object set(int index, Object element)Return Value: The element which is at the specified indexException Throws: IndexOutOfBoundsException when the index is out of range i.e, index < 0 or index >= size()Implementation: Java // Replacing Element in Java Vector import java.util.Vector; public class Sias { public static void main(String args[]) { try { // create a instance vector Vector<Integer> vector = new Vector<>(); // insert the values in vector vector.add(1); vector.add(2); vector.add(3); vector.add(4); vector.add(5); // display the vector System.out.println("original vector : " + vector); // call set() and replace 2 index value vector.set(2, 10); // display vector after replacing value System.out.println("after replace the value : " + vector); // call set() and replace 9th index value // which is exception as arrayoutofbound vector.set(9, 91); // display vector after replacing value System.out.println("after replace the value : " + vector); } catch (Exception e) { System.out.println(e); } } } Outputoriginal vector : [1, 2, 3, 4, 5] after replace the value : [1, 2, 10, 4, 5] java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 9 Time Complexity: O(n), where n is the length of the vector Comment More infoAdvertise with us Next Article Replacing Element in Java Vector M mukulsomukesh Follow Improve Article Tags : Java Java Programs Java-Vector Practice Tags : Java Similar Reads Implementing Sorted Vector in Java Vector is a class that implements the List interface. It is a type of dynamic array that means the size of a vector can be grown or shrink during the execution of the program. The initial size of the vector is 10 and if we insert more than 10 elements then the size of the vector is increased by 100% 3 min read Java Program to Search an Element in Vector A vector in Java is a dynamic array that can be resized as needed. It is synchronized, which means it is safe in multi-threaded programs. To find an element in a Vector we have to loop through its elements to find a match. In this article, we will learn how to search for a component in a Vector usin 3 min read Searching Elements in Vector Using Index in Java Vector implements a dynamic array that means it can grow or shrink as required. Like an array, it contains components that can be accessed using an integer index. An element of a Vector can be searched using an index with different methods. Suppose if the element is not present in the Vector then th 4 min read Iterate Over Vector Elements in Java Vector is like the dynamic array which can grow or shrink its size. Unlike array, we can store n-number of elements in it as there is no size limit. We can iterate over vector by the following ways: Simple for-loopEnhanced for-loopIteratorsEnumeration interface Method 1: Simple for-loop The idea is 4 min read Finding Minimum Element of Java Vector Vector implements a dynamic array that means it can grow or shrink as required. Like an array, it contains components that can be accessed using an integer index. We know two ways for declaring array i.e. either with a fixed size of array or size enter as per the demand of the user according to whic 3 min read Like