如何取map<string,int>中int最小的所有string
1个回答
展开全部
package image;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Set;
public class ThreadTest
{
public static void main ( String[] args )
{
LinkedHashMap<String, Integer> map = new LinkedHashMap<String, Integer> ();
map.put ("a", 90);
map.put ("b", 7);
map.put ("c", 15);
map.put ("d", 7);
Collection<Integer> set = map.values ();
Iterator<Integer> iterable = set.iterator ();
int min = Integer.MAX_VALUE;
while (iterable.hasNext ())
{
int i = iterable.next ();
min = min < i ? min : i;
}
System.out.println (min);
Set<String> sets = map.keySet ();
Iterator<String> it = sets.iterator ();
while (it.hasNext ())
{
String key = it.next ();
if (map.get (key) == min)
{
System.out.println (key);
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询