Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Change or Replace ArrayList Elements using set() function

import java.util.ArrayList;

class Main {
  public static void main(String[] args) {
    ArrayList<String> animals = new ArrayList<>();

    // add elements in the arraylist
    animals.add("Peacock");
    animals.add("Markhor");
    animals.add("Cow");
    System.out.println("ArrayList: " + animals);

    // change the element of the array list
    animals.set(2, "Dog");
    System.out.println("Modified ArrayList: " + animals);
  }
}
Source by softhunt.net #
 
PREVIOUS NEXT
Tagged: #Change #Replace #ArrayList #Elements #function
ADD COMMENT
Topic
Name
3+2 =