Grokking The Java Developer Interview: More Than 200 Questions To Crack The Java, Spring, SpringBoot & Hibernate Interview



Download 7,31 Mb.
Pdf ko'rish
bet73/89
Sana21.04.2022
Hajmi7,31 Mb.
#571320
1   ...   69   70   71   72   73   74   75   76   ...   89
Bog'liq
Grokking-The-Java-Developer-Interview-More-Than-200-Questions-To-Crack-The-Java -Spring -SpringBoot-

public
boolean
add(E 
e
) {
ensureCapacityInternal(
size
+ 1);
// Increments
modCount!!
elementData
[
size
++] = 
e
;
return
true
;
}
Here size is a private variable
/**
* The size of the ArrayList (the number of
elements it contains).
*
*
@serial
*/
private
int
size
;
The default value of size will be 0, so call to ensureCapacityInternal()
will have value 1, now let’s see ensureCapacityInternal() Javadoc:
private
void
ensureCapacityInternal(
int
minCapacity
) {
ensureExplicitCapacity(calculateCapacity
(
elementData
,
minCapacity
));
}
Here minCapacity is holding value 1, calculateCapacity() method is:
private
static
int
calculateCapacity(Object[]
elementData

int
minCapacity
) {
if
(
elementData
==
DEFAULTCAPACITY_EMPTY_ELEMENTDATA
) {
return
Math.max (
DEFAULT_CAPACITY
,
minCapacity
);
}
return
minCapacity
;
}


Now, as both elementData and
DEFAULTCAPACITY_EMPTY_ELEMENTDATA are same (see the
default ArrayList constructor above), if condition will be true and then
Math.max(10,1) will return 10 from calculateCapacity() method
Now, 10 will be passed to ensureExplicitCapacity()
private
void
ensureCapacityInternal(
int
minCapacity
) {
ensureExplicitCapacity(calculateCapacity
(
elementData

minCapacity
));
}

Download 7,31 Mb.

Do'stlaringiz bilan baham:
1   ...   69   70   71   72   73   74   75   76   ...   89




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish