Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. import java.util.ArrayList;
  2. public class ElementInserter {
  3. public static void main(String[] args) {
  4. ArrayList<Integer> arrayList = new ArrayList<Integer>();
  5. ArrayList<Integer> a = new ArrayList<Integer>();
  6. a.add(1);
  7. a.add(5);
  8. a.add(7);;
  9. a.add(2);
  10. a.add(11);
  11. for(int index=0; index < a.size(); index++) {
  12. arrayList.add(a.get(index));
  13. }
  14. System.out.println("Array Before Insertion:");
  15. for(int index=0; index < arrayList.size(); index++) {
  16. System.out.println(a.get(index));
  17. }
  18. System.out.println("Array After Insertion of 15 at position 3");
  19. arrayList.add(2,15);
  20. for(int index=0; index < arrayList.size(); index++) {
  21. System.out.println(arrayList.get(index));
  22. }
  23. }
  24. }
  25.  
  26. Array before insertion:
  27. 1
  28. 5
  29. 4
  30. 7
  31. 9
  32. 6
  33. Array after insertion of 15 at position 3:
  34. 1
  35. 5
  36. 4
  37. 15
  38. 7
  39. 9
  40. 6
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement