How to Change an Item in an ArrayList in Java


In this example, we will learn the method to change an item in an ArrayList in Java.

Source Code

package com.beginner.examples;

import java.util.ArrayList;

public class ChangeArrayList {
  public static void main(String[] args) {
    ArrayList strs = new ArrayList();
    strs.add("a");
    strs.set(0, "b");
    System.out.println(strs);
  }
}

Output:

[b]

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments