In: Computer Science
Explain the difference between Arrays and ArrayList. What are the limitation of arrays? How many primitive data types Java have? Please list them out and list the corresponding wrapper classes for each type. What is the different between String class and StringBuilder class?
Solution :
Q. DIFFERENCE BETWEEN ARRAY AND ARRAYLIST
Array is a fixed length data structure, that is once declared we cannot change the length of the array later while ArrayList is a part of a collection framework which is present in the package of java (java.util). It resizes itself when the capacity gets full.
If we try to store type which is not convertible into type of array, Array throws an exception. Thus we cannot use Generics along with array while ArrayList allows us to use Generics to overcome this disadvantage.
It is mandatory to specify the size of the array while we can create an ArrayList with a default value of 10 and increase it later.
Array can store both primitive data types as well as objects of a class while ArrayList can store only objects and not primitive datas
Arrays can be multi-dimensional while ArrayLIsts are always single dimensional
Q.LIMITATION OF ARRAYS
Q.LIST OUT THE DIFFERENT PRIMITIVE DATATYPES AND THEIR CORRESPONDING WRAPPER CLASS
There are 8 primitive data types in JAVA,
Q. DIFFERENCE BETWEEN STRING CLASS AND STRINGBUILDER CLASS