0% found this document useful (0 votes)
12 views

U4-IT-Collection Framework and IO Stream in Java

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

U4-IT-Collection Framework and IO Stream in Java

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 65

COLLECTION FRAMEWORK

&
I/O STREAM

1
COLLECTION FRAMEWORK IN JAVA
An array is an indexed collection of fixed no of homogeneous
data elements.
(or)
An array represents a group of elements of same data type.
The main advantage of array is we can represent huge no of
elements by using single variable. So that readability of the
code will be improved.
Example:
Student s[ ]=new Student[10000];
2
COLLECTION FRAMEWORK IN JAVA
Limitations of Array:
Arrays are fixed in size.
Arrays can hold only homogeneous data elements.
Arrays concept is not implemented based on some data
structure.

3
COLLECTION FRAMEWORK IN JAVA
The Collection in Java is a framework that provides
an architecture to store and manipulate the group of
objects.
The Java Collections Framework standardizes the way
in which groups of objects are handled by your
programs.
Collections were not part of the original Java release,
but Prior to the Collections Framework, Java provided
ad hoc classes such as Dictionary, Vector, Stack, and
Properties to store and manipulate groups of
objects. 4
COLLECTION FRAMEWORK IN JAVA
Early version of java did not include the Collections

framework. It only defined several classes and interfaces that

provide methods for storing objects.

When Collections framework were added in J2SE 1.2, the

original classes were reengineered to support the collection

interface. These classes are also known as Legacy classes.

All legacy classes and interface were redesign by JDK 5 to

support Generics. 5
COLLECTION FRAMEWORK IN JAVA
The following are the legacy classes defined by

java.util package.

Dictionary

HashTable

Properties

Stack

Vector

There is only one legacy interface called Enumeration.

NOTE: All the legacy classes are synchronized6


COLLECTION FRAMEWORK IN JAVA

7
COLLECTION FRAMEWORK IN JAVA

8
COLLECTION FRAMEWORK IN JAVA

9
COLLECTION FRAMEWORK IN JAVA

10
COLLECTION FRAMEWORK IN JAVA

11
COLLECTION FRAMEWORK IN JAVA

12
COLLECTION FRAMEWORK IN JAVA

13
COLLECTION FRAMEWORK IN JAVA

14
COLLECTION FRAMEWORK IN JAVA

15
COLLECTION FRAMEWORK IN JAVA

16
COLLECTION FRAMEWORK IN JAVA

17
COLLECTION FRAMEWORK IN JAVA

18
COLLECTION FRAMEWORK IN JAVA

19
COLLECTION FRAMEWORK IN JAVA

20
COLLECTION FRAMEWORK IN JAVA

21
COLLECTION FRAMEWORK IN JAVA

22
COLLECTION FRAMEWORK IN JAVA

23
COLLECTION FRAMEWORK IN JAVA

24
COLLECTION FRAMEWORK IN JAVA

25
COLLECTION FRAMEWORK IN JAVA

26
COLLECTION FRAMEWORK IN JAVA

27
COLLECTION FRAMEWORK IN JAVA
Comparison of Set Implemented Class Objects.

28
COLLECTION FRAMEWORK IN JAVA

29
COLLECTION FRAMEWORK IN JAVA

30
COLLECTION FRAMEWORK IN JAVA

31
COLLECTION FRAMEWORK IN JAVA

32
COLLECTION FRAMEWORK IN JAVA

33
COLLECTION FRAMEWORK IN JAVA

34
COLLECTION FRAMEWORK IN JAVA

35
COLLECTION FRAMEWORK IN JAVA

36
COLLECTION FRAMEWORK IN JAVA

37
COLLECTION FRAMEWORK IN JAVA

38
COLLECTION FRAMEWORK IN JAVA

39
COLLECTION FRAMEWORK IN JAVA

40
COLLECTION FRAMEWORK IN JAVA

41
COLLECTION FRAMEWORK IN JAVA

42
COLLECTION FRAMEWORK IN JAVA

43
COLLECTION FRAMEWORK IN JAVA

44
COLLECTION FRAMEWORK IN JAVA

45
COLLECTION FRAMEWORK IN JAVA

46
COLLECTION FRAMEWORK IN JAVA

47
SCANNER CLASS IN JAVA
The Scanner class is used to get user input, and it is
found in the java.util package.
To use the Scanner class, create an object of the class
and use any of the available methods found in
the Scanner class documentation.
To import a class or a package:

System.in is an InputStream which is typically


connected to keyboard input of console programs. 48
STREAM CLASSES IN JAVA

49
STREAM CLASSES IN JAVA
Java’s stream-based I/O is built upon four abstract
classes: InputStream, OutputStream, Reader, and
Writer.

InputStream and OutputStream are designed for


byte streams. Reader and Writer are designed for
character streams.

In general, you should use the character stream classes


when working with characters or strings, and use the
byte stream classes when working with bytes or other
50

binary objects.
STREAM CLASSES IN JAVA

51
STREAM CLASSES IN JAVA

52
STREAM CLASSES IN JAVA

53
STREAM CLASSES IN JAVA

54
STREAM CLASSES IN JAVA

55
STREAM CLASSES IN JAVA

56
STREAM CLASSES IN JAVA

57
STREAM CLASSES IN JAVA

58
STREAM CLASSES IN JAVA

59
STREAM CLASSES IN JAVA
The FileReader class creates a Reader that you can use
to read the contents of a file.

Its two most commonly used constructors are shown


here:

FileReader(String filePath)

FileReader(File fileObj)

Either can throw a FileNotFoundException.

Here, filePath is the full path name of a file, and fileObj


60
is a File object that describes the file.
STREAM CLASSES IN JAVA

61
STREAM CLASSES IN JAVA

62
STREAM CLASSES IN JAVA

63
STREAM CLASSES IN JAVA

64
Thank You
65

You might also like