User Story
Create a program that outputs the longest word in a list.
List<String> words = new List<String>{'apple', 'banana', 'grape', 'kiwi', 'orange'};
Expected Outcome
The longest word is banana.
Codes
List<String> words = new List<String>{'apple', 'banana', 'grape', 'kiwi'};
String longestWord = '';
for (String word : words) {
if (word.length() > longestWord.length()) {
longestWord = word;
}
}
System.debug('The longest word is: ' + longestWord);
Video
Video does not exists.