about | help | code help+videos | done | prefs |
Given an ArrayList of Integers called lst, add a new element at position pos, with the same value as the old element at pos. Thus, if pos is 0 and the element at index 0 has the value 3, your code would insert an additional Integer element with the value 3 such that the first two elements both now have the value 3. Return the ArrayList as output. HINT: the get method returns the element at the specified index. Example:ArrayList<Integer> myList = new ArrayList<Integer>(); myList.add(5); // myList contents: [5] myList.add(2); // myList contents: [5, 2] myList.add(1, 3); // myList contents: [5, 3, 2] System.out.println(myList.get(1)); // prints 3 (element at index 1) myList.add(myList.get(0)); // myList contents: [5, 3, 2, 5] apcsaListAddRepeat([3, 4, 5], 2) → [3, 4, 5, 5] apcsaListAddRepeat([5, 0, 3], 0) → [5, 5, 0, 3] apcsaListAddRepeat([3, 5, 6], 1) → [3, 5, 5, 6] ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 220
Copyright Nick Parlante 2017 - privacy