import java.util.*; public class LongestWord { public static List findLongestWord(String sentence) { List result = new ArrayList<>(); if (sentence == null || sentence.isEmpty()) return result; String[] words = sentence.split("\\s+"); int maxLength = 0; for (String word : words) { if (word.length() > maxLength) { maxLength = word.length(); result.clear(); result.add(word); } else if (word.length() == maxLength) { result.add(word); } } return result; } public static void main(String[] args) { String sentence = "Java is versatile"; System.out.println("Longest Word(s): " + findLongestWord(sentence)); } }