Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- public class ArrayList_185 {
- public static void main(String[] args) {
- ArrayList<Integer> arrList = new ArrayList<Integer>();//1. input list
- System.out.println(" Print first list: " + arrList.toString());//2. print the list
- arrList.add(1);//3. add elements
- arrList.add(5);
- arrList.add(7);
- arrList.add(9);
- System.out.println(" Print list with elements: " + arrList.toString());// print the list with elements
- arrList.add(2 ,8);//4. put element 8 to index 2
- System.out.println(" Print second list with elements: " + arrList.toString());// print the second list with new value
- arrList.remove(3);//5. remove the value of index 3
- System.out.println("Remove index 3: " + arrList.toString());
- arrList.remove(Integer.valueOf(5));//6. remove the value 5
- System.out.println("Remove value of 5: " + arrList.toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement