Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assume that you have the following class OurContainer. In this class you have three collections and three methods that return the sum of the elements

image text in transcribed
image text in transcribed
Assume that you have the following class OurContainer. In this class you have three collections and three methods that return the sum of the elements in the collections. Do they work? Discuss the pros and cons of these three approaches (they use for, for each and iterator). Would all these methods work if you change the collection kind? public class OurContainer private HashSet Integer> ; private ArrayList y private HashMapcInteger, Integer z; public OurContainer() x-new HashSet(); y = new ArrayList(); = new HashMapc>(); // code to populate these collections with integers 3 public int use For Iteration() C int sum = 0; for (int n. enz.size(); n.-) sum - sum + z.get(n); return sum public int useForEachiteration Ant > public int useForEachIteration() int sume: for (Integer ny) { sumsum + n; return sum; 3 public int useIteratorIteration() int sum = 0; for (Iterator it = x.iterator(); it hasNext()) { sum - sum + it.next(); 1 return sum; 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Bioinformatics Databases And Systems

Authors: Stanley I. Letovsky

1st Edition

1475784058, 978-1475784053

More Books

Students also viewed these Databases questions