Changing Values in an ArrayList Object
E set (int index, E e)
The method changes the value at index to be e and returns the previous value at index.
Your Turn
Let's try it in the Java Playground.
- Predict the output of the code.
- Run the code to determine if your prediction is correct.
- Write code to change the first element of
studentListto "John". Predict the output of the code and run it to determine if your prediction is correct.
Complete List of ArrayList Tutorials
- Learn: Constructing an ArrayList Object
- Learn: Adding Values to an ArrayList Object
- Learn: Accessing and Removing Values from an ArrayList Object
- Learn: Changing Values in an ArrayList Object
- Learn: Analyzing an ArrayList Object
- Learn: Iterating Over an ArrayList Object