answersLogoWhite

0


Best Answer

If you want to compare two HashSet objects, you have very few choices. The obvious choice is to use the .equals method built into the implementation. If that doesn't work for you, then you have to use the Iterator returned by the .iterator method, which is functionally the same as using the for-each loop.






The Comparable Interface can be used to compare two hashsets.
Use compareTo() method.
User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How efficiently to compare 2 HashSets in Java without to use foreach cycle?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Is it mandatory to use array in foreach loop C-sharp can foreach be used without array?

Foreach is for an IEnumerable, not just an array (unless you are using C# 1.1 or earlier). A collection (List, Dictionary, etc) can also generate a sequence from foreach-statement. In fact, if you have a class that is NOT an array, but it implements all the required methods of IEnumerable, it may be applied as:public class Storage: IEnumerable {...}Storage myStorage = new Storage();...Foreach (Thing stuff in myStorage){...}


Why is important for us to use technology effectively and efficiently?

Technology is what makes us powerful as a species; without it we would just be a hairless ape.


How do you compare two numbers without using any operators in c?

You cannot compare 2 numbers without using relational operators. Certainly, you could subtract them, but you still need to test the result, and that is a relational operator in itself.


What is more efficient heat pumps with or without gas back-up?

with gas back up . a heat pump alone ,will not be able to extract heat efficiently when it reaches it's economic balance point in its region of operation.


How do you know Ryb phases when color coding is not there?

First of all, the colours red, yellow, and blue, are applied to LINES not to phases! To determine which line is which, you must compare them with lines that are identified. This process is known as 'phasing out', and is difficult to explain without using a diagram. I suggest you check out 'phasing out' on the internet.

Related questions

Is it mandatory to use array in foreach loop C-sharp can foreach be used without array?

Foreach is for an IEnumerable, not just an array (unless you are using C# 1.1 or earlier). A collection (List, Dictionary, etc) can also generate a sequence from foreach-statement. In fact, if you have a class that is NOT an array, but it implements all the required methods of IEnumerable, it may be applied as:public class Storage: IEnumerable {...}Storage myStorage = new Storage();...Foreach (Thing stuff in myStorage){...}


How can a need become a want?

When you are no longer able to survive or function efficiently without the thing in question.


Write the different modes of communication and compare them?

Modes oftransportation... Lets see: car, train, bus, boat, plain. They all forms of ways you can get some where faster and more efficiently without wasting any energy at all practically.


How do you make your nose smaller efficiently without cosmetic surgery?

Makeup.


When a person is performing in the best possible way without wasting time or effort he or she is working .?

efficiently


When a person is performing in the best possible way without wasting Time or effort he or she is working?

efficiently


How can i build a fence without drilling into concrete cheaply and efficiently?

Use materials other than concrete.


What word describes to do something without wasting any more time?

Expedite: to deal with quickly and efficiently


How do plants survive in the desert without water?

By procuring the moisture from air and soil and conserving it very efficiently.


Explain why a person without a gallbladder is unable to digest fats as efficiently as someone who has a gallbladder?

Because of the liver


Do you need a thermostat?

Vehicle will run without a thermostat - however will not run as efficiently and will have not heat


What cooking technology heats food very efficiently without heating the cooking surface?

Ceramic glass cooktop