Collection interface in java Collection interface in java 6 Collection interface in java example Collection interface api Collection interface methods in java Collection interface methods Collection interface api java
what are methods available in Collection interface Collection interface examples in java Collection interface example program example program for Collection interface in java
Collection
Interface :
Collection is one
of the predefined interface on the top of all 1D collection frame
interfaces.
An object of collection interface allows duplicate elements. It allows us to
add
the data only at end but not at the specific position. Object of collection
allows us to display
the data in random order and it allows to retrieve the
data only in forward but not in backward
direction.
Profile Of
Java.util.collection :
1) Public int size() :
This method is used for finding the number of elements present in any
collection frame
work variable.
2) Public Boolean isEmpty():
This method returns true provided collection frame work variable does
not contain any
element (Empty).
This method returns false provided collection frame work variable
contain some elements
(Non-empty).
3) Pubic Boolean add(object):
This method is used for adding any type of value to any collection frame
work variable.
This method returns Boolean as return type.
As long as we call add() w.r.t collection and
List interface objects then this
method returns true. In case of set ans sorted set if we call
this method by
adding unique it also returns true.
If we try to add duplicate elements to set and sorted set then this
method returns false.
4) Public Boolean addAll(Collection):
This method is used for adding the content of one collection frame
variable to another
collection frame work variable.
5) Public Iterator iterator():
The method iterator() retrives all the elements of any collection frame
work variables and
forms like a chain in the chain of elements, just before the
first element an object of Iterator
interface object is pointing.
For
Example :
System.out.println(C1);//[10,20,30,40]
Iterator itr=c1.iterator();
int s=0;
while(itr.hasNext())
{
Object obj=itr.next();
Integer uo=(Integer)obj;
int x=io.intValue();
System.out.println(x);//10,20,30,40
s=s+x;
}
6) Public object[] toArray() :
This
method is used for retrieving all the elements of collection frame work
variable and places in array
of objects of Java.lang.Object.
When object of
java.lang.object is holding every type of value, what is need of
collection
frame work?
An object of
java.lang.object is holding multiple values of same types or different
types.
But the array of objects of java.lang.object is containing
fixed size in nature and
they are not expandable. Hence in order to hold multiple values of
same type or different
type with dynamic size in nature we use the concept of collection frame work.
Data Extraction Interfaces are as follows :
1- D and 2-D Collection Frame work classes are
6) TreeSet
No comments:
Post a Comment