Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
The Vector
class is a growable array of objects. The elements of Vector
can be accessed using an integer index and the size of a Vector can be increased or decreased.
Read more about
Vector
here.
The setElementAt
method of the Vector
class can be used to replace the element present at the specific index of the vector object.
public void setElementAt(E obj,int index)
This method takes two arguments.
vector
object.vector
object. Otherwise, ArrayIndexOutOfBoundsException
will be thrown.index
>= 0 && index
< size()
This method doesn’t return any value.
import java.util.Vector;
class SetElementAt {
public static void main( String args[] ) {
// Creating Vector
Vector<Integer> vector = new Vector<>();
// add elememts
vector.add(10);
vector.add(40);
vector.add(30);
System.out.println("The Vector is: " + vector); // [10,40,30]
vector.setElementAt(20, 1); // [10,20,30]
System.out.println("\nAfter calling setElementAt(20,1). The Vector is: " + vector);
}
}
In the code above:
10,40,30
, to the created vector object.setElementAt
method of the vector
object to replace the element present at index 1
with the value 20
. Now, the vector will be 10,20,30
.In our experience, we suggest you solve this What is the Vector.setElementAt method in Java? and gain some new skills from Professionals completely free and we assure you will be worth it.
If you are stuck anywhere between any coding problem, just visit Queslers to get the What is the Vector.setElementAt method in Java?
I hope this What is the Vector.setElementAt method in Java? would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.
This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.
Keep Learning!
More Coding Solutions