Generic
|
Non generic
|
The collection that can hold same data type is called Generic.
|
The collection that can hold different data type is called Non generic.
|
Type casting is not required
|
Typecasting is required.
|
Type safe and compile time checking
|
Not Type safe and run time checking
|
Syntax: Class Or Interface<Type>
Example: Suppose you are creating an object of ArrayList Class then write like this..
ArrayList<String> A1 = new ArrayList<String>();
A1.add("DEV");
A1.add(“Surya”);
A1.add(“Madhu”);
Explanation:
You can add only string value because you define the datatype as String
in ArrayList and you know that it holds same data type.
|
Syntax: Class Or Interface
Example: Suppose you are creating an object of ArrayList Class then write like this..
ArrayList A1=new ArrayList();
A1.add(12);
A1.add(“Ram”);
A1.add(15.75);
Explanation:
You can add any value(int,double,string) because there is no data type mentioned in ArrayList
and you know that it holds different datatype.
|
Tuesday, 5 December 2017
Difference between Generic and Non generic collections?
Subscribe to:
Post Comments (Atom)
apply function in R
1) apply function: It takes 3 arguments matrix,margin and function.. Example: m<-matrix(c(1,2,3,4),nrow=2,ncol=2) m #1 indicates it is ap...
-
a)Structural diagrams Structure diagrams depict the static structure of the elements in your system.It shows the things in the system - ...
-
index.html <html> <head><title>Sum of two numbers</title></head> <body> <form method="pos...
-
Write a program to input marks of five subjects Physics, Chemistry, Biology, Mathematics and Computer, calculate percentage and grade acc...
No comments:
Post a Comment