How to replace an element at specific index in ArrayList with Java

1 Answer

0 votes
import java.util.*;

public class MyClass {
    public static void main(String args[]) {
        
        ArrayList<String> al = new ArrayList<String>();  
      
        al.add("java");
        al.add("c++");
        al.add("c#");
        al.add("python");
        al.add("c");
        al.add("php");
        al.add("javascript");
        
        al.set(3, "ELEMENT");
        
        System.out.println(al); 
    }
}


/*
run:

[java, c++, c#, ELEMENT, c, php, javascript]

*/

 



answered Apr 27, 2020 by avibootz

Related questions

1 answer 302 views
2 answers 346 views
1 answer 274 views
2 answers 311 views
1 answer 281 views
1 answer 270 views
...