DEV Community

velvizhi Muthu
velvizhi Muthu

Posted on

Module 5-Collection and ArrayList

01. Dis Advantage of array?
1.Limitation of arrays
Once we create an array,its size can't change.
If we want to add more elements, we need a new array.

  1. Only stores Homogeneous data. Array can store only one type of data. we can't mix int and String. 3.No ready -made methods Arrays don't have built-in methods for common tasks like sorting,Adding/Removing elements. 4.Memory wastage if the array is too large,unused positions want memory If it is too small,we need to create a new array.

02.What is Collection?

  1. A Collection represents a single unit of objects.
  2. Collection is a framework.
  3. Collection is a interface in java.util package.
  4. We can't create an object directly.

03.What are the Types of collection?
There are three types of Collection.
1.List
2.set
3.Queus

04. What is the List?

  1. List is an interface in java.util package.
  2. We can't create an object directly.
  3. It contains dulicate value.
  4. It define some methods like add(),get(),remove(),size().

05.What are the types of the List?
There are two types of list.
1.ArrayList
2.LinkedList

06.What is the ArrayList?
1.ArrayList is a class in Java.util package.
2.ArrayList class implements the list interface.
3.It uses a dynamic array to store the duplicate elements of different data types.
4.The elements stored in the ArrayList class can be randomly accessed.

07. How do you create an arraylist in java?
ArrayList list = new ArrayList<>();

08.What is the Frame work?
1.A frame work is a predefined structure.
2.That provide ready-made tools,Libraries and classes to help developers build application efficiently.

Benefits:

1.Reusable packages and classes.
2.Reduces development time.
3.Quality
4.Speed

09.What is the collection frame work?
The Collection framework represents a unified architecture for storing and manipulating a group of objects.

10.Why collection frame work?
1.Efficient Data Structures
2.Reusability & Maintainability

  • You can reuse and extend collection classes without rewriting code.
  • It improves code readability and maintainability.

11.Advantages of collection frame work?
1.Collections solve all array problems and provide many built-in features.
2.Dynamic size
3.Heterogeneous data
4.Predefined methods
Easy operations: add,remove,sort
ex: Collections.sort(list);
5.Better performance in real project
Optimized for searching,insertion,deletion.

*12. What are the Methods of ArrayList? *

1.Add:
Add the student in a school.
Ex:
list.add("Kayal");
list.add("Vizhi");
list.add("Hi");
list.add(10);
System.out.println(list);
2.Get method:
Get student at a postion
EX:
Object get =list.get(0);
System.out.println(get);

3.set method:
Update student name
Ex:
list.set(0, "Kumar");
System.out.println(list);

4.Remove method:
Remove the index (Ex: Index 0)
Remove student by position.
Remove student by name
Ex:
list.remove("Vizhi");
System.out.println(list);

5.Size method:
Count how many student are present
Ex:
System.out.println(list.size());

6.Contains method:
Check if a student is present
True or false condition checking methods.
Ex:
boolean con =list.contains("Kayal");
System.out.println(con);

7.Isempty();Method
Check if no one is present.

Ex:
boolean empty=list.isEmpty();
System.out.println(empty);

8.Clear();
Remove all students records
Empty symbol []
Ex:
list.clear();
System.out.println(list);

13. What is the Iterate Interface

The iterator interface provides the facility of iterating the elements in a forward direction only.

Top comments (0)