編輯:關於Android編程
int MAX = 100000; long start = System.currentTimeMillis(); HashMap代碼2:hash = new HashMap (); for (int i = 0; i < MAX; i++) { hash.put(i, String.valueOf(i)); } long ts = System.currentTimeMillis() - start;
int MAX = 100000; long start = System.currentTimeMillis(); SparseArray上面兩段代碼中,我們分別用HashMap和SpaseArray正序插入100000條數據,數據如下:sparse = new SparseArray (); for (int i = 0; i < MAX; i++) { sparse.put(i, String.valueOf(i)); } long ts = System.currentTimeMillis() - start;
int MAX = 100000; long start = System.currentTimeMillis(); HashMap代碼4:hash = new HashMap (); for (int i = 0; i < MAX; i++) { hash.put(MAX - i -1, String.valueOf(i)); } long ts = System.currentTimeMillis() - start;
int MAX = 100000; long start = System.currentTimeMillis(); SparseArraysparse = new SparseArray (); for (int i = 0; i < MAX; i++) { sparse.put(MAX - i -1, String.valueOf(i)); } long ts = System.currentTimeMillis() - start;
public void put(int key, E value) { int i = binarySearch(mKeys, 0, mSize, key); if (i >= 0) { mValues[i] = value; } else { i = ~i; if (i < mSize && mValues[i] == DELETED) { mKeys[i] = key; mValues[i] = value; return; } if (mGarbage && mSize >= mKeys.length) { gc(); // Search again because indices may have changed. i = ~binarySearch(mKeys, 0, mSize, key); } …………
private static int binarySearch(int[] a, int start, int len, int key) { int high = start + len, low = start - 1, guess; while (high - low > 1) { guess = (high + low) / 2; if (a[guess] < key) low = guess; else high = guess; } if (high == start + len) return ~(start + len); else if (a[high] == key) return high; else return ~high; }
HashMap時,我們可以使用如下的方式來取得更好的性能.hashMap = new HashMap ();
SparseArraysparseArray = new SparseArray ();
一、assets/xml/raw資源介紹 1.assets資源目錄:assets目錄下存放的資源代表應用無法直接訪問的原生資源,這些文件將原封不動的存儲到設備上,不會被編
在Android開發中,我們常用的布局方式主要有LinearLayout、RelativeLayout、FrameLayout等,通過這些布局我們可以實現各種各樣的界面。
上篇文章介紹了Android開發的設計理念的一部分,並沒有得到博友們的多大認可,只看到了一位博友在下面留言期待下一篇文章的發表,為了這小小的唯一支持,我決定繼續把後面的8
介紹A text field allows the user to type text into your app. It can be either single li