markLength4
Category: ArrayList
Author: Stuart Reges
Book Chapter: 10.1
Problem: markLength4
Write a static method markLength4 that takes an
ArrayList of Strings as a parameter and that places a String of four
asterisks ("****") in front of every String of length 4. For example,
suppose that an ArrayList called "list" contains the following values:
(this, is, lots, of, fun, for, every, Java, programmer)
And you make the following call:
markLength4(list);
Then list should store the following values after the call:
(****, this, is, ****, lots, of, fun, for, every, ****, Java, programmer)
Notice that you leave the original Strings in the list (this, lots, Java)
but include the four-asterisk String in front of each to mark it. You may
assume that the ArrayList contains only String values, but it might be
empty. Recall that the primary methods for manipulating an ArrayList are:
add(Object value) appends value at end of list
add(int index, Object value) inserts given value at given index,
shifting subsequent values right
get(int index) returns the value at given index
remove(int index) removes value at given index, shifting
subsequent values left
set(int index, Object value) replaces value at given index with
given value
size() returns the number of elements in list
Write your solution to markLength4 below.