Cursors:

An idicator used to show current position for respective object or element.

Four types of Curdors:

Enumerattion:

it can be used only for read…

Stack:

Underlying data structure of Stack is Stack.

Stack based on LIFO.

Allows duplicate elements.

insertion order is preserved.

Accepts heterogenous Objects.

Based on LIFO.

Ex:

package com.java.hackerrank.corejavacollections.stsck;

import java.util.Stack;

/**
*
@Author pankaj
*
@create 1/16/22 10:51 PM
*/
public class StsckEx {
public static void main(String[] args) {
Stack stack = new Stack();
stack.push(20);
stack.push(41);
stack.push(78);
stack.push(75);
stack.push(false);
Object o = stack.pop();
System.out.println(stack);
System.out.println(stack.peek());
System.out.println(stack);
boolean b = stack.isEmpty();
System.out.println(b);
System.out.println(stack.search(78));// return position

}
}

O/P:

[20, 41, 78, 75]
75
[20, 41, 78, 75]
false
2

Vector:

Underlying data structure is Resizable and Growable Array.

Underlying data Structure of Vector is Array.

Allows duplicates.

insertion order is preserved.

Accepts heterogeneous objects.

Vector implements Serizable clonable and Random Access interfaces.

All the methods of Vector is synchronized.(Single thread can access method at a time), Hence vectors are thread safe.

ArrayList vs Vector??

ArrayList:

Methods in arraylist are not synchronized, Not thread safe.

Performance relatively high.

Not legacy class(java 1.2)

Vector:

All methods in Vector are synchronized.

Performance relatively Low.

Legacy class(java 1.0)

ArrayList:

Not recommended to use for insertion and deletion in middle.

Best choice for retrieving operations.

LinkedList:

best choice for insertion and deletion in middle.

Not recommended for retrieval operations.

LinkedList:

LL is DS where every element is separate object with data and address part. Each element is called as Node(data+address)

Duplicate elements are allowed in LL.

heterogeneous elements are allowed.

Null insertion is possible.

Insertion order is preserved.

Example:

package com.java.hackerrank.corejavacollections;

import javax.swing.*;
import java.util.Collection;
import java.util.LinkedList;

/**
*
@Author pankaj
*
@create…

List:

List is an ordered collection.

List allows positional access to Elements.

Note: All the list implementation classes (ArrayList, LinkedList, Vector, Stack) .All are ordered collection that allows duplicates.

Example:

package com.java.hackerrank.corejavacollections.ArrayList;

import java.util.*;

/**
*
@Author pankaj
*
@create 1/16/22 6:50 PM
*/
public class ArrayListDemo {
public static…

Collection Framework: added in 1.2 V

Set of Interfaces, implementation classes and algorithms.

The purpose of the Collection framework is to put all classes, interfaces algorithms at once place, So that programmer can use them in and deal with his data.

Note: A collection framework consists of three things.

Collection:

A group of individual Object.

Collection are grow-able in nature.

They can be homogeneous or heterogeneous.

Diff b/e Array and Collection:

Array:

Fixed in size.

Can hold only homogeneous types.

In memory point of view , we should not use Arrays.[Not recommended in memory point of view]

There are no underlying Data structures.[because array it self is a data structure]

Don’t have build in method like sorting, searching,

Array can hold both primitive type and object type.

Collection:

Collection are grow-able in nature.

Can hold homogeneous or heterogeneous.

Recommended to use to stop memory wastage as it grows on demand.

In built data structures and algorithms.[Ex for Array list array is underlying DS]

Have build in method like sorting, searching,[ we have default utility support ]

It can only hold object types.

Pankaj Kumar Ravi

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store