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


Question 97: What is default size of ArrayList?



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

Question 97: What is default size of ArrayList?
Answer: 10
/**
* Default initial capacity.
*/
private
static
final
int
DEFAULT_CAPACITY
= 10;
Question 98: Which data structure is used internally
in an ArrayList?
Answer: Internally, ArrayList uses Object[]
/**
* The array buffer into which the elements of the
ArrayList are stored.
* The capacity of the ArrayList is the length of
this array buffer. Any


* empty ArrayList with elementData ==
DEFAULTCAPACITY_EMPTY_ELEMENTDATA
* will be expanded to DEFAULT_CAPACITY when the
first element is added.
*/
transient
Object[] 
elementData
;
Question 99: How add() method works internally or
How the ArrayList grows at runtime
Answer: this is what happens when we create an ArrayList object
using its default constructor,
/**
* Constructs an empty list with an initial
capacity of ten.
*/
public
ArrayList() {
this
.
elementData
=
DEFAULTCAPACITY_EMPTY_ELEMENTDATA
;
}
Here, elementData is a transient variable and
DEFAULTCAPACITY_EMPTY_ELEMENTDATA is an empty Object[]
array:
transient
Object[] 
elementData
;
private
static
final
Object[]
DEFAULTCAPACITY_EMPTY_ELEMENTDATA
= {};
Now, let’s see Javadoc of add() method
/**
* Appends the specified element to the end of this
list.
*
*
@param
e element to be appended to this list
*
@return

true

(as specified by
{@link
Collection#add}
)


*/

Download 7,31 Mb.

Do'stlaringiz bilan baham:
1   ...   68   69   70   71   72   73   74   75   ...   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