Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. In what programming situations would the use of an array be beneficial? 2. Wh

ID: 3706928 • Letter: 1

Question

1. In what programming situations would the use of an array be beneficial? 2. What situations would not warrant the use of an array? Provide an example explaining why? 3. Imagine a programming structure that would deal with these problems. What characteristics should the structure possess? 4. Research the concept of class ArrayList in Java. Describe the advantage of using the ArrayList class over an array. Also discuss in what circumstances you should use one over the other. Please use examples to justify your answers.

Explanation / Answer

1 )

Array will be usefull of you know the size in advance because arrays are fixed in size and can't grow if you know the size in advnace than it is good to use arrays

If your operations or searching elements than array is better option as it based on Index searching will be fast

2) if you dont know the size in advance than it is not suggested to use arrays and if your frequent operations or insertion and deletion than its not good to use arrays because when you made any insertion in the middle or starting than you should shuffle all the elements to the right which is time consuming process

3) depends on the requirement it should decide which one to use

4) ArrayList is Collection class which is used to store the hetrogenious elements and it is groawble in size. initially it is created with size 10 once it is filled size will be increased. ArrayList will allow the duplicate elements and it follow the insertion orde

Syntax:

ArrayList <Integer>list = new ArrayList<Integer>

if you know the size in Advance than you can use the arrays and if your requirement is dynamic than you should use the ArrayList

because if you declare an array with size 10 but you want store more than 10 elements than it is not possible to do that in arrays , where as in ArrayList we can do that because ArrayList are growable in size

Arrays: if you want to store the hours in day than we can use arrays because we know it is fixed in size with 24

ArrayList : if you want to store the prime numbers in range , because you dont know hom many numbers you will get