Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

An ArrayList is a special type of container that acts much like a StringBuilder class, but it can hold generic elements. The type of elements

An ArrayList is a special type of container that acts much like a StringBuilder class, but it
can hold generic elements. The type of elements an ArrayList will actually hold is usually
predetermined at declaration (so a little more general than just holding characters). The
elements are stored in a sequence like an array, but the array is dynamic like StringBuilder,
in that it can grow, shrink, have elements inserted/removed, etc. It also supports more
functions like sorting, shuffling & reversing elements. This makes them far more powerful
than your typical array (which is fixed in size).
An ArrayList is generally declared along with the Type that of its elements (specified inside
angle brackets <>). Here are some sample declarations (note the type in the <> MUST
be a reference type, you cannot use primitive types!!
ArrayList myIntList;
ArrayList myDoubleList;
ArrayList myStringList;
ArrayList myPictureList;
Each of these variables myXXXList represents a reference to an ArrayList<> object that
would need to be instantiated this is generally done using a default constructor, which
also uses the ArrayList format. Here are the declarations + instantiations together:
ArrayList myIntList = new ArrayList();
ArrayList myDoubleList = new ArrayList();
ArrayList myStringList = new ArrayList();
ArrayList myPictureList = new ArrayList();
If instantiated this way, the list is considered an empty list of elements of the provided type,
(much like an array with no elements). Then through methods like add() and remove(),
elements can be added to the list either at the end (one version of add method), or inserted
at a location (another version of add). Likewise for removing elements.
The goal of this question is to read through the input file TreasureIsland.txt, and to identify
(using regex + matches method), any words that end in ing(upper or lower case). Upon
finding such words, add them to an ArrayList of String elements.
Once done reading from TreasureIsland.txt, you should then open a new file
(wordsFound.txt) for writing (see Lecture 03, slides 7-29 for information on
reading/writing to a file). In this output file, write the words discovered under a title, it
should look something like this:
Words found ending in ing
===========================
word[0]-> following
word[1]-> HESITATING
word[2]-> FIGHTING
word[3]-> having
word[4]-> beginning
word[5]-> keeping
word[6]-> nothing
word[7]-> lodging
word[8]-> plodding
word[9]-> following
word[10]-> falling
word[11]-> looking
...
There is no tester for this question, check your output file when done (there should be
thousands of words in it. Make sure your pattern matching accounts for any leading
punctuation characters that are not part of the word).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions