package main;import java.util.ArrayList;import java.util.Arrays;import java.util.Collection;import java.util.Collections;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Set;import java.util.TreeSet;import javax.print.attribute.HashAttributeSet;public class 发过的 { public static void main(String[] args) { ArrayListarrayList =new ArrayList<>(); arrayList.add("sdfsdfs"); arrayList.add("sdwerwerfsdfs"); arrayList.add("werwr"); arrayList.add("we"); arrayList.add("sdfswewdfs"); arrayList.add("werwewrwerwerwrw"); arrayList.add("wwerwerwewesfsdrwrew"); getMinValue(arrayList); System.out.println("最小Value是:::::::::::::"+ getMinValue(arrayList));// HashMap hashMap=new HashMap ();// for (String string : arrayList) {// int len=string.length();// hashMap.put(string.length(), string);// }// // Iterator > entries = hashMap.entrySet().iterator(); // while (entries.hasNext()) { // Map.Entry entry = entries.next(); // System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue()); // }// // Set set = hashMap.keySet();// Object[] obj = set.toArray();// Arrays.sort(obj);// System.out.println(obj[0]);// // String resultValue = "";// //根据key ,找Value// for(Map.Entry str : hashMap.entrySet()){// if(obj[0].equals(str.getKey())){// resultValue = str.getValue();// }// }// System.out.println("最小Value是:::::::::::::"+resultValue); } private static String getMinValue( ArrayList arrayList) { //定义一个map来存截取的数据 HashMap hashMap=new HashMap (); for (String string : arrayList) { int len=string.length(); hashMap.put(string.length(), string); } //获取所有的key值 Set set = hashMap.keySet(); Object[] obj = set.toArray(); //排序 Arrays.sort(obj); //最小的Value值的变量 String resultValue = ""; //根据key ,找Value for(Map.Entry str : hashMap.entrySet()){ if(obj[0].equals(str.getKey())){ resultValue = str.getValue(); } } return resultValue ; } }