Limited access

Upgrade to access all content for this subject

Consider the following code, which was written to remove all job titles that are long (greater than 20 characters). jobs is a String ArrayList of job titles.

    ArrayList<String> jobs = // full of job titles

    for (int i=0; i<jobs. size(); i++)
    {
        if (jobs.get(i).length()>20)
        {
            jobs.remove(i);
        }
    }

Which of the following BEST describes the results of executing this code and whether it will function as intended?

A

Yes, it will remove all job titles from jobs.

B

No, it is not checking the length of a job title correctly.

C

No, it is not accessing an element from jobs correctly within the loop.

D

No, if two long job titles are next to each other in jobs, it will not remove the second one.

E

No, it will throw an error if the last job title in jobs is greater than 20 characters long.

Select an assignment template