Question

Remaining Time: 1 hour, 59 minutes, 35 seconds. Question Completion Status: What is the primary difference between a Set and a Map? T T T Arial , J (12p?. T . :-·-·?·ees Path p QUESTION 54 Explain briefly the operation of each of the tollowing Iterator-related methods a) iterator b) hasNext c) next Click Save and Submit to save and submit.Ciek Save Al Ansers to save all ansvers
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Difference between Set and Map

If we want to represent a group of objects as single entity where duplicates are not allowed and insertion order is not preserved then we should prefer Set

In set it allows at most one single value

If we don’t want to allow duplicates in the database then we should go for Set

If we want to represent a group of objects as key value pairs then we should go for Map.Where Map doesn’t allow duplicate keys but duplicate values are allowed.

Map allow at most one null value as key and any number of null as values

In Map ,insertion order is not preserved.

_______________

iterator():

If we call this method on the collection class(Ex: ArrayList) then we will get an Iterator class.Which is used to iterate over the ArayList.

Ex:

ArrayList<Integer> arl=new ArrayList<Integer>();

Iterator it=arl.iterator();

______________

hasNext():

We call this method on the Iterator class to check whether it has next element or not.If it has next element it will return true,otherwise it will return false.

________________

next() :

This method is used to get the next element .If we have next element it returns that element ,otherwise it throws NoSuchElementException.

_______________Thank You

Add a comment
Know the answer?
Add Answer to:
Remaining Time: 1 hour, 59 minutes, 35 seconds. Question Completion Status: What is the primary difference...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT