Question

In: Computer Science

Explain the difference between Arrays and ArrayList. What are the limitation of arrays? How many primitive...

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?

Solutions

Expert Solution

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

  1. Array is static in nature. Hence once the size is specified it cannot be changed later on.
  2. Array occupies contiguous memory location hence scattered memory locations cannot be used in case we are to use an array of big size.
  3. The time complexity increases during insertion and deletion operations

Q.LIST OUT THE DIFFERENT PRIMITIVE DATATYPES AND THEIR CORRESPONDING WRAPPER CLASS

There are 8 primitive data types in JAVA,

  1. bool - its size is 1 bit. Its corresponding class is Boolean
  2. byte - its size is 8 bits. Its corresponding class is Byte
  3. char - its size is 16 bits. Its corresponding class is Character
  4. short - its size is 16 bits. Its corresponding class is Short
  5. int - its size is 32 bits. Its corresponding class is Integer
  6. long - its size is 64 bits. Its corresponding class is Long
  7. float - its size is 32 bits. Its corresponding class is Float
  8. double - its size is 64 bits. Its corresponding class is Double

Q. DIFFERENCE BETWEEN STRING CLASS AND STRINGBUILDER CLASS

  1. String is immutable in nature while StringBuilder is mutable.
  2. It is thread safe while StringBuilder is not.
  3. Strings are used when we dont have to change the input much while StringBuilder is used0 when its going to change often with single thread

Related Solutions

What is the difference between primitive types and abstract datatypes?
What is the difference between primitive types and abstract data types?
Explain what is the limitation of the Profit Margin On Sales and explain the limitation of...
Explain what is the limitation of the Profit Margin On Sales and explain the limitation of return on assets.
What is the difference between a pdf and a cdf? How are they related? Explain this...
What is the difference between a pdf and a cdf? How are they related? Explain this as you would to someone who wasn't in class when I did. Assume they have taken Calculus 2. You can use text, pictures, a video, a dance, a song... whatever you want. Be creative! Submit your explanation as one file (a pdf for text or image, a single video or audio file etc.)
Explain the difference between IPv4 and IPv6 addressing schemes and discuss that how many different IPv4...
Explain the difference between IPv4 and IPv6 addressing schemes and discuss that how many different IPv4 and IPv6 addresses are available for computers on the Internet?
Explain how arrays allow you to easily work with multiple values? Explain the relationship between the...
Explain how arrays allow you to easily work with multiple values? Explain the relationship between the length and valid indexes of an array? Why do we need to pass a size as well as the array to any function/procedure where we want it to use this array? Explain how for loops can be used to work effectively with elements in an array? How could you print out the names in the array starting with the last name and working back...
what is the difference between monopoly and oligopoly ? explain how the demand and the supply...
what is the difference between monopoly and oligopoly ? explain how the demand and the supply behave in the two cases?
What is the difference between ALE and MPAL? Explain how each is calculated. (This is for...
What is the difference between ALE and MPAL? Explain how each is calculated. (This is for a Security Risk Analysis class.)
How many levels of virtualization can one consider? Comment on their advantages, shortcoming, and limitation. What...
How many levels of virtualization can one consider? Comment on their advantages, shortcoming, and limitation. What are the typical systems that you know of that have been implemented at each level in the past? What are the difference between full virtualization and paravirtualization? Explain at the advantages, and shortcomings, and limitation in the implementation and applications of either class of VMs on today’s host machines.
Explain the difference between substrate-level phosphorylation and oxidative phosphorylation? How many ATPs (net) are made by...
Explain the difference between substrate-level phosphorylation and oxidative phosphorylation? How many ATPs (net) are made by substrate-level phosphorylation vs oxidative phosphorylation in aerobic respiration? What role does chemiosmosis play?
1. Explain the difference between an elastic and inelastic collision. 2. How many times more energy...
1. Explain the difference between an elastic and inelastic collision. 2. How many times more energy is required to increase the speed of a 2200 pound car by 10 mph if car initially is going 30 mph versus it initially going 80 mph? (convert to metric) 3. how many horse power are required to accelerate from 80 mph to 90 mph in 0.75 seconds? (tell me the average horsepower. 1 horsepower = 750 watts) 4. will a solid lead cylinder...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT