編輯:關於Android編程
HashMap排序是數據結構與算法中常見的一種排序算法。本文即以Android平台為例來實現該算法。
具體代碼如下:
public static void main(String[] args) {
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("lisi", 5);
map.put("lisi1", 1);
map.put("lisi2", 3);
map.put("lisi3", 9);
List<Map.Entry<String, Integer>> infoIds = new ArrayList<Map.Entry<String, Integer>>(
map.entrySet());
System.out.println("--------------排序前--------------");
for (int i = 0; i < infoIds.size(); i++) {
String id = infoIds.get(i).toString();
System.out.println(id);
}
// 排序
Collections.sort(infoIds, new Comparator<Map.Entry<String, Integer>>() {
public int compare(Map.Entry<String, Integer> o1,
Map.Entry<String, Integer> o2) {
return ( o1.getValue()-o2.getValue());
}
});
System.out.println("--------------排序後--------------");
for (int i = 0; i < infoIds.size(); i++) {
Entry<String,Integer> ent=infoIds.get(i);
System.out.println(ent.getKey()+"="+ent.getValue());
}
}
希望本文所述的HashMap排序算法能對大家的算法學習有所幫助。
Android 自定義圓形帶刻度漸變色的進度條樣式實例代碼
效果圖一、繪制圓環圓環故名思意,第一個首先繪制是圓環1:圓環繪制函數圓環APIpublic void drawArc (RectF oval, float startAn
Android ListView的item點擊無響應的解決方法
如果listitem裡面包括button或者checkbox等控件,默認情況下listitem會失去焦點,導致無法響應item的事件,最常用的解決辦法 是在listite
Android Tab -- 使用ViewPager、Fragment、FragmentPagerAdapter來實現
效果:滑動切換;點擊標簽切換。 代碼:https://github.com/ldb-github/Layout_Tab1、布局:使用LinearLayout布置
Android開發之初識MVP模式
各位親愛的小伙伴,有沒有想我啊,我胡漢wing又回來了。很長一段時間沒有更新博客。。原因是。。從離職回到學校以後,一直在享受最後的學生時光(打游戲).. 游戲固然很爽,但