public static String test(){ String str = "hello wordss yes i do go houses"; String[] words = str.split(" "); List<String> list1 = new ArrayList<String>(); List<Integer> list2 = new ArrayList<Integer>(); for(String word : words){ list1.add(word); list2.add(word.length()); } int maxLength = 0; String maxStr = ""; for(int i=0;i<list2.size();i++){ if(maxLength<list2.get(i)){ maxLength = list2.get(i); maxStr = list1.get(i); } } System.out.println("第一个最长的单词:"+maxStr); return maxStr; }