An array is an indexed collection of fixed no of homogenous elements
it represents same group
fixed size no increasing or decreasing
student[] s=new student[10];
Collections are growable in size
hold both homogeneous and non homogeneous
implemented based on some standard datastructure
--------------------------------------------------------------------
Arrays Collections
Fixed Growable
Mem not Recommended Mem Recommended
Only Homogeneous Hetrogeneous
no underlying Ds standard DS
noready made ready made avaialble
primitives
objects only objs
---------------------------------------------------------------------
Collection
If u Want to rpresent a Group of individual objs then go for Collection
List:
child interface of Collection
dup allows and insertion order preserved
colection
list
ArrayList
LinkedList
Vector
Stack
------------------------------------------------------------------------
Set:
child interface of Collection
dup allows insertion order not preserved
Collection
Set
HashSet -----------LinkedHashSet
SortedSet------NavigableSet--TreeSet
--------------------------------------------------------------------------
SortedSet:
child of Interfadce of set
dup not allows only sorting order
----------------------------------------------------------------------------
NavigableSet:
child inf of sortedset
provides navigation process
------------------------------------------------------------------------------
Queue:
child interface of Collection
---------------------------------------------------------------------------------------------------------
group of objects in key value Maps::::::::::;
Map:
Dupkeys are not allowed vals be duplicated
Map:
HashMap-------------------LinkedHashMap
IdentityHashMap----------------WeakHashMap
SortedMap-------------------NavigableMap------------TreeMap
Dictionary
---------------------------------------------------------------------------------------
SortedMap:
child of Map
group of <k,v> pairs according to some order
-----------------------------------------------------------------------------------------
Navigable Map:
methods for navigation
----------------------------------------------
Collection--------------interface
collections------------class
legacy Characters:
Enumeration(i)
Dictionary(Ac)
Vector(c)
Stack(c)
HashTable(c)
Properties(c)
Methods in Collection Interface:
add(Object o)
addall()
remove()
removeall()
retainall()
clear()
containsall()
isEmpty()
size()
toArray()
iterator()
list Interface:
add(int index,Object o)
addAll()
Object get()
Object remove(int index)
Object set(int index,Obj new)
indexof()
Listitereator()
ArrayList:
dup allowed
insertion preserved
het allowed
Linkedlist::
addFirst()
last
get
remove
Vector:::::::;;
-->resizable/growable Array
-->Duplicates objects are allowed
-->Insertion order is preserved
-->Heterogeneous allowed
-->Null version is possible
add(Object o)
add(int index,Object o)
addElement(Object o)
cursors of JAVA:::
If we want to get objects one by one from the collection then we shoild go for cursor.
1.Enumeration
2.Itereator
3.ListIterator
Enumeration:
we can get Enumeration to get objects one by one from the legacy collection objects
we can create Enumeration object by using elements() method
Enumeration interface defines the following methods::
1. public boolean hasMoreElements();
2.public Object nextElement();
limitations of Enumeration::
we can use Enumeratoin only for classes and it is not universal cursor
we perform only read opeartions
we can't perform remove operations
to overcome we use Iterator
No comments:
Post a Comment