Java原始碼閱讀之Vector

2021-07-10 08:38:45 字數 3127 閱讀 6054

vector與arraylist區別:

protected object elementdata;

protected int elementcount;

protected int capacityincrement;

private static final int max_array_size = integer.max_value - 8;

//預設構造乙個10大小的object陣列

public vector()

public vector(int initialcapacity)

public vector(int initialcapacity, int capacityincrement)

//該方案同arraylist的是一樣的

public synchronized void ensurecapacity(int mincapacity)

}private void ensurecapacityhelper(int mincapacity)

private void grow(int mincapacity)

private static int hugecapacity(int mincapacity) 

public synchronized void trimtosize()

}

方法主要完成了跟add、remove、insert等方法的功能;

方法主要在stack子類中被使用;

setsize():

//指定限制當前vector的大小;

public synchronized void setsize(int newsize) else

}elementcount = newsize;

}

elements():

//類似迭代器的方式訪問vector資料

public enumerationelements()

public e nextelement()

}throw new nosuchelementexception("vector enumeration");}};

}

elementat():

//讀取指定位置資料

public synchronized e elementat(int index)

return elementdata(index);

}

firstelement():

//返回第乙個資料

public synchronized e firstelement()

return elementdata(0);

}

lastelement():

//返回最後乙個資料

public synchronized e lastelement()

return elementdata(elementcount - 1);

}

setelementat():

//改變指定位置引用的物件

public synchronized void setelementat(e obj, int index)

elementdata[index] = obj;

}

insertelementat():

//插入資料到指定位置

public synchronized void insertelementat(e obj, int index)

ensurecapacityhelper(elementcount + 1);

system.arraycopy(elementdata, index, elementdata, index + 1, elementcount - index);

elementdata[index] = obj;

elementcount++;

}

addelement():

//新增物件到陣列末尾

public synchronized void addelement(e obj)

removeelement():

//根據物件移除資料

public synchronized boolean removeelement(object obj)

return false;

}

removeelementat():

//根據index移除資料

public synchronized void removeelementat(int index)

else if (index < 0)

int j = elementcount - index - 1;

if (j > 0)

elementcount--;

elementdata[elementcount] = null; /* to let gc do its work */

}

removeallelements():

//移除所有的元素;即將object陣列中的每個引用賦值為null

public synchronized void removeallelements()

原始碼閱讀 Glide原始碼閱讀之with方法(一)

前言 本篇基於4.8.0版本 原始碼閱讀 glide原始碼閱讀之with方法 一 原始碼閱讀 glide原始碼閱讀之load方法 二 原始碼閱讀 glide原始碼閱讀之into方法 三 大多數情況下,我們使用glide 就一句 但是這一句 裡面蘊含著成噸的 with方法有以下幾個過載方法 publi...

原始碼閱讀 Glide原始碼閱讀之load方法(二)

原始碼閱讀 glide原始碼閱讀之load方法 二 原始碼閱讀 glide原始碼閱讀之into方法 三 首先,load方法有以下幾個過載方法 public requestbuilder load nullable bitmap bitmap public requestbuilder load nu...

《原始碼閱讀》原始碼閱讀技巧,原始碼閱讀工具

檢視某個類的完整繼承關係 選中類的名稱,然後按f4 quick type hierarchy quick type hierarchy可以顯示出類的繼承結構,包括它的父類和子類 supertype hierarchy supertype hierarchy可以顯示出類的繼承和實現結構,包括它的父類和...