collections in java is data structure to hold different objects and iterate them through different inbulit functions. I defined collections with small letter becoz there is another Collections class in java.util package which contains static utility function which operates on collection of objects.
collections -> data structure to hold objects (or framework).
Collections -> class inside java.util package contains static methods which iterates over collections object.
Collection - > Collection interface is on the top of hierarchy which is extended by list, queue and set. Map is not a part of Collection but collections. As i said collections is way to store objects. Map use to store object using key-value pair.
It is not a part of Collection becoz their methods or operation is different than list, queue. It does n't implement any of the methods of Collection interface. Thats why it is not a part of Collection interface.
How many interfaces and concrete classes in collections framework ?
Concrete classes r the classes which implements interfaces in java. In fig when you see red circle which means a interface otherwise concrete class.
What is difference b/w ArrayList and Vector ?
Vector and Arraylist methods r same bt Vector methods r more likely synchronized.
Difference b/w ArrayList and LinkedList ?
ArrayList use index for any of the operations like removal, insertion and updation while LinkedList can be iterate whether from beginning or top not from middle.
Difference b/w Set and List ?
Set doesn't allow duplicates items while list allows duplicates. Random output in case of set.
Difference b/w Map and Set ?
Map contains key-value pair, all objects(values) store through key. Autoboxing is automatically performed by java complier So primitive types convert into respective wrapper objects.
Some common methods in coolection framework (not for Map)
->public boolean addAll(collection c)
->public boolean add(object a)
->public boolean remove(Object a)
->public boolean removeAll(collection c)
->public int size()
->public boolean contains(object a)
->public boolean containsAll(collection c)
->public Iterator iterator()
-> Arrays.asLists(arrayname)
->public int hashcode()
->public boolean equals(coolection c)
Comparable interface is used to compare values of user defined data types. It uses compareTo(object a) for this purpose.
Comparator interface defined in java.lang package, it consists 2 member functions equals(), public int compare(Object b1, Object b2).
Maps Methods-
put(key,value);
get(key);
like - put(1,"i m unemployed);
to get the value we use get(key) function
System.out.println(get(1));
Properties classes is where both key and value both r strings.
sort() is used to sort elements of list or subclasses.
TreeSet provides us sorted elements of set and same for TreeMap.
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment