ArrayList in Java Part2- Collection Frame Work series- Java Complete course
You can learn Java with me as the Java Programming language is being made easily. It would take a period of minimum three months and maximum 6 months to master Java. I would recommend you to watch all my videos to crack any software interviews that would require Java Programming language as a primary skill.
Collection Framework:-
=======================
ArrayList:-
============
1. It is a class in Java collection framework.
2. ArrayList implements List interface.
3. ArrayList was introduced in the JDK1.2 version
4. ArrayList is in java.util package.
5. By default, the initial capacity of ArrayList is 10.
6. ArrayList is an index based array where the insertion order is preserved.
7. ArrayList allows duplicate values
8 ArrayList does not follow sorting order.
9. ArrayList allows heterogenous elements for non-generic type.
10. ArrayList allows homogeneous elements for the generic type.
11. The ArrayList is resizable in nature.And its incremental capacity is as follows
INCREMENTALCapacity =(CurrentCapacity *(3/2))+1);
12. When you want to retrieve the data frequently, you can go for arraylist. It is faster when you use it to retrieve the data.
13. ArrayList is non synchronized in nature.
14 . It is not a thread safe.
15. It cant be used in the Multithreaded environment
16. Its performance is high because it is non synchronized.
17 . It lacks data consistency.(data could be compromised)
Syntax of ArrayList:-
====================
Non-Generic type:
=================
ClassName/InterfaceName referenceVariable =new ClassName/InterfaceName():
Generic type:
=============
ClassName/InterfaceName WrapperClass referenceVariable =new ClassName/InterfaceName WrapperClass ():
There are 2 types of syntax:-
===============================
1. Non-Generic Type ArrayList obj=new ArrayList();
2. Generic Type ArrayList String obj=new ArrayList String ();
Methods in ArrayList:-
=================
1. boolean add(Object obj):-
=============================
This method is used to add the element and the index number will be generated at the time of adding the elements and if it is added successfully. It returns true.
2. int size();
===============
This method is used return the size of the given ArrayList. The size is not but the number of values that are added inside the ArrayList.
3. int get(int index);
========================
This method is used to return the values that is on top of respective index.
4. boolean isEmpty();
======================
This method is going to return the true value if the method is empty or else it will return false
5. int indexOf(Object obj):
============================
This method is going to return the index number of the respective object value that is passed inside the method parameter. If the value does not exists, it will return -1.
6. boolean contains(Object obj):
================================
This method is going to return the Boolean value as true if the element is present or else it will return false .
7. int lastIndexOf(Object obj):
================================
This method is going to return the last index number of the respective object value that is passed inside the method parameter. If the value does not exists, it will return -1.
8. void add(int index, Object value):
=====================================
This method will allow you to add the specific value on top of the give index number. And, the existing value on that respective index will be shifted to the right direction.
Please be informed that if you are add an element on an index number that is not exist, than you will get the below error.
java.lang.IndexOutOfBoundsException: Index: 10, Size: 7
9. int set(int index, Object value);
=======================================
This method is used to set a particular value on top of the respective index and the value that is already there will be returned
10 boolean addAll(Object obj):
==============================
This method will add all the elements from one object that is placed in the parameter to another object . This will successfully return the value true if the elements are added.
11. boolean addAll(int index, Object obj):
==========================================
This method will add all the elements from one object that is placed in the parameter to another object from the respective index . This will successfully return the value true if the elements are added.
Видео ArrayList in Java Part2- Collection Frame Work series- Java Complete course канала Learn Java
Collection Framework:-
=======================
ArrayList:-
============
1. It is a class in Java collection framework.
2. ArrayList implements List interface.
3. ArrayList was introduced in the JDK1.2 version
4. ArrayList is in java.util package.
5. By default, the initial capacity of ArrayList is 10.
6. ArrayList is an index based array where the insertion order is preserved.
7. ArrayList allows duplicate values
8 ArrayList does not follow sorting order.
9. ArrayList allows heterogenous elements for non-generic type.
10. ArrayList allows homogeneous elements for the generic type.
11. The ArrayList is resizable in nature.And its incremental capacity is as follows
INCREMENTALCapacity =(CurrentCapacity *(3/2))+1);
12. When you want to retrieve the data frequently, you can go for arraylist. It is faster when you use it to retrieve the data.
13. ArrayList is non synchronized in nature.
14 . It is not a thread safe.
15. It cant be used in the Multithreaded environment
16. Its performance is high because it is non synchronized.
17 . It lacks data consistency.(data could be compromised)
Syntax of ArrayList:-
====================
Non-Generic type:
=================
ClassName/InterfaceName referenceVariable =new ClassName/InterfaceName():
Generic type:
=============
ClassName/InterfaceName WrapperClass referenceVariable =new ClassName/InterfaceName WrapperClass ():
There are 2 types of syntax:-
===============================
1. Non-Generic Type ArrayList obj=new ArrayList();
2. Generic Type ArrayList String obj=new ArrayList String ();
Methods in ArrayList:-
=================
1. boolean add(Object obj):-
=============================
This method is used to add the element and the index number will be generated at the time of adding the elements and if it is added successfully. It returns true.
2. int size();
===============
This method is used return the size of the given ArrayList. The size is not but the number of values that are added inside the ArrayList.
3. int get(int index);
========================
This method is used to return the values that is on top of respective index.
4. boolean isEmpty();
======================
This method is going to return the true value if the method is empty or else it will return false
5. int indexOf(Object obj):
============================
This method is going to return the index number of the respective object value that is passed inside the method parameter. If the value does not exists, it will return -1.
6. boolean contains(Object obj):
================================
This method is going to return the Boolean value as true if the element is present or else it will return false .
7. int lastIndexOf(Object obj):
================================
This method is going to return the last index number of the respective object value that is passed inside the method parameter. If the value does not exists, it will return -1.
8. void add(int index, Object value):
=====================================
This method will allow you to add the specific value on top of the give index number. And, the existing value on that respective index will be shifted to the right direction.
Please be informed that if you are add an element on an index number that is not exist, than you will get the below error.
java.lang.IndexOutOfBoundsException: Index: 10, Size: 7
9. int set(int index, Object value);
=======================================
This method is used to set a particular value on top of the respective index and the value that is already there will be returned
10 boolean addAll(Object obj):
==============================
This method will add all the elements from one object that is placed in the parameter to another object . This will successfully return the value true if the elements are added.
11. boolean addAll(int index, Object obj):
==========================================
This method will add all the elements from one object that is placed in the parameter to another object from the respective index . This will successfully return the value true if the elements are added.
Видео ArrayList in Java Part2- Collection Frame Work series- Java Complete course канала Learn Java
#javaShorts #balaji m #java #computers #JavaInterviewQuestions #Learn Java #coding #programming #developer #arraysinjava #lengthvariable #fixedsizearray #arraydatastructureinjava #homogeneousarray #arraysproblem #arraysproblemsapproach #arraylistinjava #collections #collectionframeworkinjava #arraylist #linkedlist #vector #stack #listinterface #collectioninterface #queueinterface #setinterface #dyanmicarray #heterogeneouselements #addmethod #setmethod #addallmethod #get #indexofmethod
Комментарии отсутствуют
Информация о видео
20 июня 2024 г. 20:57:42
01:13:22
Другие видео канала