Nothing Special   »   [go: up one dir, main page]

Collection and Database Programing PART1

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 23

Collection And Database

Programming
Introduction
Data Structure-It is using data in memory in a Efficient manner.
Time and Space Complexity is seen here.
It has various algorithms for searching, sorting, insertion, manipulation, and deletion.

Data Structure is of 2 Types


1. Primitive – int,char,bool,byte,short,long,float,double
2.Non Primitive-
Linear DS: String,Arrays,List,Set,Queve,Linked List,Hashset,Linked Hash set.
Non Linear DS: Grpah,Trees.

Collection Framework(marked red) has classes which can be directly used. It is


predefined by Java.
Collection
• The Collection in Java is a framework that provides an
architecture to store and manipulate the group of objects.
• Java Collections can achieve all the operations that you
perform on a data such as searching, sorting, insertion,
manipulation, and deletion.
• Java Collection means a single unit of objects. Java Collection
framework provides many interfaces (Set, List, Queue, Deque)
and classes (Array List, Vector, LinkedList, PriorityQueue,
HashSet, LinkedHashSet, TreeSet).
• Collection- Single entity or object to store multiple data.
• Framework- Represents the Library. Has Predefined Classes and Interface used to
store multiple data.
• java.util.Collection
• java.util.Map

• Collection is interface present in java.util package.

• Syntax-
Array vs ArrayList
• Arrays: Used to Save Primitive and Non Primitive Data Type.
Saves Homogeneous contents.
Cannot increase or decrease size of Array during Runtime.
Need to Develop algorithm for Sorting, Searching etc.

• ArrayList: Stores Non Primitive Type.


Values we pass are created as Objects.
Eg: ArrayList al= new ArrayList();
al.add(10)- Here 10 is passed as Object is the ArrayList

• Heterogeneous Element can be added in ArrayList.


al.add(10)
al.add(‘x’)- We have then added another object in ArrayList.
• As Classes and Interface of Inbuilt are there. So no need to have algoriythm for
Sorting,Searching etc.
Methods in Collection Interface:
List and Set
• List: Based on Index
Can store Duplicate Elements.
Any number of null values can be stored.
Follows Insertion Order.
To get elements from List, we can use Iterator(forward) or ListIterartor(backward).

• Set: Stores by Hascode values.


No Duplicate Elements.
Only One null Value.
Does not Follow Insertion Order.
To get elements from List, we can use Iterator.
• If we want to retrieve element one after another, we use CURSOR.
• CURSOR- 3 types
Iterator
ListIterator
Enumeration
Iterator:
1. Iterator cursor gets by iterator();
Iterator lr= l.iterator();
2. It can be used for any Collection Object.
3. Iterator methods are hashnext(),next() and remove().
4. By using Iterator we can retrieve only forward direction.
Using Iterator we can read &remove elements.
5. It is Uinversal Cursor.

ListIterator:
2. ListIterator cursor gets by listiterator();
ListIterator lr= l.listiterator();
2. It can be used for Listt Implemented Classes
. ArrayList,LinkedList,Vector,Stack.
3. Iterator methods are hashnext(),next(), hashprevious(),previous() remove(),set().
4. By using Iterator we can retrieve forward and backward direction.
Using Iterator we can read, remove,replace and add elements.
5. It is used opnly for List Implement Classes only.
Enumeration in Java
• Enemuration is cursor which is used to return collection of object one by one.
• Used for Legacy Classes- Vector, Stack.
• Enumeration cursor gets through elements().
Enumeration e=v.elements();
Methods in Enumeration:
hasMoveElements(), nextElement().
• Enumeration cursor can be used to return elements in Forward Direction.
• It cannot remove elements.
• Enumeration can be used only to read Operation

You might also like