Question: import java.util.List; import java.util.ArrayList; /* * * This program loops through an array list of strings and finds the longest string */ public class FindLongest

import java.util.List;
import java.util.ArrayList;

/*
*
*  This program loops through an array list of strings and finds the longest string
*/
public class FindLongest
{
  /*
   * Given the array list of strings, return the longest string
   */
public static String findLongest(ArrayList list)
{
//-----------Start below here. To do: approximate lines of code = 8
// loop through the list of strings and check to see if
  // the string length is > the current longest string. If so, update the
  // longest string length. Be sure to create a variable to hold the longest string itself
  // as well as the length













//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}

public static void main(String[] args)
{
ArrayList elems = new ArrayList();
String[] words = {"singapore", "cattle", "metropolitan", "turnstile", "city", "deviation"};
for (int i = 0; i < words.length; i ++)
{
elems.add(words[i]);
}
System.out.println(findLongest(elems));
System.out.println("Expected:metropolitan");
elems.clear();
System.out.println(findLongest(elems));
System.out.println("Expected:");
}
}


P.S: Please write the code as well as include screenshots for reference along with output

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

import javautilList import javautilArrayList This program loops through an array list of strings and ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!