A Refference Guide of Java Collection - Day1

10
Chapter 1 Collection Framework Apex T. G. India Pvt. Ltd Introduction

description

Collection is introduced in 1.2 version of java under util package. It is a framework. It is interface that inherits Iterable interface and Object class.www.apextgi.in

Transcript of A Refference Guide of Java Collection - Day1

Chapter 1

Collection Framework

Apex T. G. India Pvt. Ltd

Introduction

1

Collection Collection is introduced in 1.2 version of java under util

package.

It is a framework. It is a framework.

It is interface that inherits Iterable interface and Object

class.

public interface java.util.Collection<E extends java.lang.Object> extendsjava.lang.Object implements java.lang.Iterable<E>

1

Collection It provides and structure to represent the group

of elements as a single unit.

It perform operation on the elements such as insertion It perform operation on the elements such as insertion

,deletion, searching, sorting etc on the elements.

It is group of heterogeneous types of elements but we can

make it homogeneous using generics.

1

Collection It is dynamic by nature,it maintain the size of collection

elements it self.

It can generate result in ordered and unordered. It can generate result in ordered and unordered.

It is very similar to array.

All collection frameworks classes and interface belongs to

util package.

1

Collection Hirarchy

1

Array vs. Collection Array and Collection both represent group of elements as a

single unit but array work on datatypes where as collection

work on Object.work on Object.

Array is static by nature where as Collection is dynamic by

nature.

Array use contiguous memory allocation where as

collection doesn't.

1

Methods of Collection(I)public interface java.util.Collection<E extends java.lang.Object>

extends java.lang.Object implements java.lang.Iterable<E>

public abstract int size(); public abstract int size();

public abstract boolean isEmpty();

public abstract boolean equals(java.lang.Object);

public abstract int hashCode();

1

Methods of Collection(I) public abstract boolean contains(java.lang.Object);

public abstract java.util.Iterator<E> iterator();

public abstract java.lang.Object[] toArray(); public abstract java.lang.Object[] toArray();

public abstract <T extends java/lang/Object> T[]

toArray(T[]);

public abstract boolean add(E);

public abstract boolean remove(java.lang.Object);

1

Methods of Collection(I) public abstract boolean containsAll(java.util.Collection<?>);

public abstract boolean addAll(java.util.Collection<? extends

E>);E>);

public abstract boolean removeAll(java.util.Collection<?>);

public abstract boolean retainAll(java.util.Collection<?>);

public abstract void clear();

ThanksStay Connected with us for more chapters on JAVA

facebook.com/apex.tgi

twitter.com/ApextgiNoida

pinterest.com/apextgi