You never really understood why there had to be so many different kinds of collections in Java, so you decide to test various collections (ArrayList, LinkedList, and set-implemented using HashSet) to see if you can detect any difference between them. You remember hearing that some of the differences are only readily apparent when you are working with very large collections so you write the following core code to create your collection (described on pseudocode)
For i from 0 to 100,000;
Generate a random value between 1 and 100, inclusive
Add the value to each your collections
Answer the following questions related to the characteristics and behavior of each Of your collections(you have named your collection objects myArrayList, myLinkedList, and mySet)
Question10. List the numbers of elements in each collection(I.e number items in each coloection):
-myArrayList:-___________
-myLinkedList:____________
– mySet:_____________
Question11. select from the following possibilities when answering the questions below:
-None
-Once
-Approximately 100
-Approximately 1000
-Approximately 10,000
How many times would you expect the value “50” to occur in each collection (select from a-e below
Expert Answer
Size of array list and linked list would be 100,000, but size of hashset would be 100 (or may be less) because list allows duplicate entries, but set doesn’t allow duplicates
So 50 is expected to be found in linked list and array list are 1,000 times and once in hashset for the very same reason.