X592: getLongestString

This method takes an ArrayList of Strings as a parameter and returns the longest String in the list. If the list is empty, it should return an empty String. If there are more than one Strings with the max length, it should return the first one with the longest length. For example, if an ArrayList variable called list stores: {"once", "upon", "a", "time"}, the method should return “once”.

Examples:

getLongestString(new java.util.ArrayList(){{add("once");add("upon");add("a");add("time");}}) -> "once"

Your Answer:

Feedback

Your feedback will appear here when you check your answer.