id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

apcsaListAddSize


Given an ArrayList of Integers called lst, insert a new element at index pos, the value of which is the size (number of elements) of the ArrayList. Note that this works easily because the size is an int and the ArrayList stores Integers. Return the modified ArrayList as output.


Precondition: pos will not be negative, and will always be less than the number of elements in lst.
HINT
The add method with two parameters uses the first parameter as the new index.

apcsaListAddSize([3, 4, 5], 2) → [3, 4, 3, 5]
apcsaListAddSize([5, 0, 3], 0) → [3, 5, 0, 3]
apcsaListAddSize([1, 2, 4, 5, 6, 10], 3) → [1, 2, 4, 6, 5, 6, 10]

...Save, Compile, Run (ctrl-enter)

public ArrayList<Integer> apcsaListAddSize(ArrayList<Integer> lst, int pos) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 220

Copyright Nick Parlante 2017 - privacy