Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- public class ElementInserter {
- public static void main(String[] args) {
- ArrayList<Integer> arrayList = new ArrayList<Integer>();
- ArrayList<Integer> a = new ArrayList<Integer>();
- a.add(1);
- a.add(5);
- a.add(7);;
- a.add(2);
- a.add(11);
- for(int index=0; index < a.size(); index++) {
- arrayList.add(a.get(index));
- }
- System.out.println("Array Before Insertion:");
- for(int index=0; index < arrayList.size(); index++) {
- System.out.println(a.get(index));
- }
- System.out.println("Array After Insertion of 15 at position 3");
- arrayList.add(2,15);
- for(int index=0; index < arrayList.size(); index++) {
- System.out.println(arrayList.get(index));
- }
- }
- }
- Array before insertion:
- 1
- 5
- 4
- 7
- 9
- 6
- Array after insertion of 15 at position 3:
- 1
- 5
- 4
- 15
- 7
- 9
- 6
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement