Collection is used for storing objects ,data etc in a tree , linked list etc.
-> suppose u want 2 objects to be stored u use a linked list or a vector
Generics are templates
ie suppose u don't know the datatype of parameters that will be passed to a func
eg
1 swap(int a, int b)
2 swap (float a,float b)
3 swap(string a,string b)
where swap func swaps the value of a ,b in all 3 cases
u know that ur login for all the 3 cases is same but the parameters passed will be of different type(int ,float,string)
instead of using overloaded func and doing the reword
u can use generic template will will handle all of the data at runtime
> Generics are templates
Not quite.
> ie suppose u don't know the datatype of parameters
Then Generics are not really what you need. Generics are used to specify the type.
> that will be passed to a func
> eg
> 1 swap(int a, int b)
> 2 swap (float a,float b)
> 3 swap(string a,string b)
All of them methods you'll never see in Java, as Java always passes by value.
> where swap func swaps the value of a ,b in all 3
> cases
> u know that ur login for all the 3 cases is same but
The login?
> the parameters passed will be of different type(int
> ,float,string)
> instead of using overloaded func and doing the
> reword
> u can use generic template will will handle all of
> the data at runtime
What are you talking about?
> What is the use of Assertions,Collections,Generics in
> java?
> I have gone through the SUN material also regarding
> these topics but it is yet not clear for me.
> Please help me.
What material did you go through, and what didn't you understand?