Welcome to Java4u

A Single Place for all Java Resources

Looking for something?

Subscribe to this blog!

Receive the latest posts by email.

.Just enter your email below if you want to subscribe!

Email

Tuesday, August 31, 2010

Collections FAQs

Q1.  What are limitations of object Arrays? 

      The main limitations of Object arrays are
  • These are fixed in size ie once we created an array object there is no chance of increasing or decreasing size based on our requirement. Hence  If we don’t know size in advance , arrays are not recommended to use
  • Arrays can hold only homogeneous elements. 
  • There is no underlying data structure for arrays and hence no readymade method support for arrays. Hence for every requirement programmer has to code explicitly
       To over come  these problems collections are recommended to use

Q2. What are differences between arrays and collections?


Arrays
Collections
1.  Arrays r fixed in size and hence once we created an array we are not allowed to increase or decrease the size based on our requirement. 1. Collections are growable in nature and hence based on our requirement we can increase or decrease the size.
2.  Memory point of view arrays are not recommended to use 2. Memory point of view collections are recommended to use.
3. Performance point of view arrays are recommended to use 3. Performance point of view collections are not recommended to use.
4.  Arrays can hold only homogeneous elements 4. Collections can hold both homogeneous and heterogeneous elements.
5. Arrays can hold both primitives as well as objects 5. Collections can hold only objects.
6. For any requirement, there is no ready method support compulsory programmer has to code explicitly. 6. For every requirement ready made method support is available. Being a programmer we have to know how to use those methods and we are not responsible to implement those.

Q3. what are differences between arrays and ArrayList?
        
         Refer  the answer of  Q2

Q4. What are differences between arrays and Vector?
   
        Refer the answer of Q2

Q5. What is Collection API ?

It defines set of classes and interfaces which can be used for representing a group of objects as single entity

Q6.  What is Collection framework?

 It defines set of classes and inter faces which can be used for representing a group of objects as single entity

Q7.  What  is difference between Collections and Collection?

Collection is an interface which can be used for representing a group of individual objects as single entity  and it acts as root interface of collection frame  work.

Collections is an utility class to define several utility methods for Collection implemented class objects.

Q8.  Explain about Collection interface?
  • This interface can be used to represent a group of objects as a single entity.
  • It acts as root interface for entire collection framework.
  • It defines the most commonly used methods which can be applicable for any collection implemented class object
Q9. Explain about List interface?
List interface is a child interface of Collection interface. This can be used to represent group of individual objects in as a single entity where
  • Duplicates are allowed
  • Insertion order is preserved
Q10.  Explain about Set interface?

Set is a child interface of Collection interface. it can be used to represent a group of individual objects as a single entity where
  • Duplicate objects are not allowed.
  • Insertion order is not preserved.

 1 2 3 4 5 6 Next>

    0 comments: