How set value at specific index in ArrayList with Java

1 Answer

0 votes
import java.util.*; 
  
public class MyClass {
    public static void main(String args[]) {
        ArrayList<Integer> al = new ArrayList<Integer>(Arrays.asList(5, 2, 9, 7, 1)); 
 
        al.set(0, 300);

        for (Integer n : al) {
            System.out.println(n);
        }
    }
}
  
  
  
  
/*
run:
  
300
2
9
7
1
  
*/

 



answered Sep 5, 2020 by avibootz

Related questions

2 answers 228 views
1 answer 182 views
1 answer 187 views
1 answer 206 views
...