2016 - 2024

感恩一路有你

java 以map的value排序 map中的value怎么设置为integer?

浏览量:4131 时间:2023-07-05 21:30:00 作者:采采

map中的value怎么设置为integer?

MapString,Integer map new HashMap();

string数组类型的map怎么取?

ListgtlistnewArrayListgt()

Mapmap

for(inti0i()

map.put(#34name#34,#34king#34i)

(map)

}

for(Mapmap2:list){

(#34map的值:#34(#34name#34))

}

如何取得map里key得最大值?

象在map里取key的大值是先排序,之后收起大的一个再试一下。

importjava.util.HashMapimportclassMaxMapDemo{publicstaticvoidmain(String[]args){MapltInteger,Integergt map new HashMapltInteger,Integergt()(1,8)(3,12)(5,53)(123,33)map.put(42,11)(44,42)(15,3)(getMaxKey(map))(getMaxValue(map))}/***求MapltK,Vgt中Key(键)的的最值*@parammap*@return*/statestaticObjectgetMaxKey(MapltInteger,Integergt map){if(mapnull)returnnullSetltIntegergtset()Object[]string()(elem)returnobj[()-1]}/***求MapltK,Vgt中Value(值)的的最值*@parammap*@return*/publicstaticObjectgetMaxValue(MapltInteger,Integergt map){if(mapnull)returnnullCollectionltIntegergtc()Object[]string()(obj)returnobj[()-1]}}

map MapltInteger Vgt

版权声明:本文内容由互联网用户自发贡献,本站不承担相关法律责任.如有侵权/违法内容,本站将立刻删除。