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

 

apcsaListFirstCharacters


Given an ArrayList of Strings, return a new List of Strings where each element contains the first character of the same-index input String.


Precondition: every element of lst will have length > 0.
FYI
The data type of the output is List<String> just because CodingBat does not allow the creation of methods with a return type of ArrayList<String>. Because an ArrayList is-a List, you can safely pretend that the return type is ArrayList<String> instead of trying to create something called a List. The AP CSA curriculum used to require that students know what a List is (an interface), but no longer requires that knowledge.
HINT
You will need a loop for this. Also remember to declare and instantiate (and return) a new ArrayList.

apcsaListFirstCharacters(["Hello", "world"]) → ["H", "w"]
apcsaListFirstCharacters(["I", "am", "legend"]) → ["I", "a", "l"]
apcsaListFirstCharacters(["Crunchy chewy", "Awesome", "Nice and sweet", "Delightful and delicious", "Yummy treat"]) → ["C", "A", "N", "D", "Y"]

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

public List<String> apcsaListFirstCharacters(ArrayList<String> lst) { }

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