java 以map的value排序 map中的value怎么設(shè)置為integer?
map中的value怎么設(shè)置為integer?MapString,Integer map new HashMap();string數(shù)組類型的map怎么取?ListgtlistnewArrayListg
map中的value怎么設(shè)置為integer?
MapString,Integer map new HashMap();
string數(shù)組類型的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]}}