Advertisement
Petra_Abrasheva_185

ArrayList_Integer

Mar 2nd, 2021
676
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. public class ArrayList_185 {
  4.  
  5.     public static void main(String[] args) {
  6.         ArrayList<Integer> arrList = new ArrayList<Integer>();//1. input list
  7.  
  8.         System.out.println(" Print first list: " + arrList.toString());//2. print the list
  9.  
  10.         arrList.add(1);//3. add elements
  11.         arrList.add(5);
  12.         arrList.add(7);
  13.         arrList.add(9);
  14.         System.out.println(" Print list with elements: " + arrList.toString());// print the list with elements
  15.  
  16.         arrList.add(2 ,8);//4. put element 8 to index 2
  17.         System.out.println(" Print second list with elements: " + arrList.toString());// print the second list with new value
  18.  
  19.         arrList.remove(3);//5. remove the value of index 3
  20.         System.out.println("Remove index 3: " + arrList.toString());
  21.  
  22.         arrList.remove(Integer.valueOf(5));//6. remove the value 5
  23.         System.out.println("Remove value of 5: " + arrList.toString());
  24.     }
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement