Can someone explain the Set class in java?
-
I'm completely lost in my computer science class. For my current assignment, I have to create methods for a program utilizing the Set class. These are the methods I need to complete: Set create(int maxsize): Creates a new Set with the specified maximum possible size (maximum number of values that can be stored in the set). boolean add(Set set, double value): Try to add the given value to the set, and return true if successful. boolean remove(Set set, double value): Try to remove the given value from the set, and return true if successful. boolean contains(Set set, double value): Return true if the given value is in the set, and false otherwise. String getString(Set set): Return a string representation of the set. The string returned should begin and end with curly braces, and in between it should contain the values in the set, in any order, separated by commas. The last value should not be followed by a comma. For example, a Set object containing the values 48, 2, 375, and 63 should return a string such as: {48.0, 2.0, 375.0, 63.0} Set union(Set set1, Set set2): Compute the union of the two sets: a new set containing all of the values in both sets. For example, the union of the sets {4, 9, 2} and {3, 2, 8, 4} is {4, 9, 2, 3, 8}. Return the result as a new Set object. Do not change either of the two original Set objects. If both sets are empty, return an empty set, not null. Set intersection(Set set1, Set set2): Compute the intersection of the two sets: a new set containing only those values that appear in both this set and the other. For example, the intersection of the sets {4, 9, 2} and {3, 2, 8, 4} is {4, 2}. Return the result as a new Set object. Do not change either of the two original Set objects. If there are no values that appear in both sets, return an empty set, not null. Set difference(Set set1, Set set2) Compute the difference of the two sets: a new set containing only those values that appear in this set, but not in the other. For example, the difference of the sets {4, 9, 2} and {3, 2, 8, 4} is {9}. Return the result as a new Set object. Do not change either of the two original Set objects. If there are no values that appear in this set but not the other, return an empty set, not null. Does anyone know how to do ANY of these? Any help at all would be greatly appreciated.
-
Answer:
Obviously you do not read any of your given documentation, since you are just trying to implement a built in class.... Here are some references where you can read about the class. http://java.sun.com/j2se/1.4.2/docs/api/java/util/Set.html http://www.exampledepot.com/egs/java.util/coll_Sets.html
ladeedah at Yahoo! Answers Visit the source
Related Q & A:
- Can someone explain what is a logical drive?Best solution by ehow.com
- Can someone explain the finacial crisis?Best solution by Yahoo! Answers
- Can someone explain slingbox to me?Best solution by Yahoo! Answers
- Can someone explain what sailing is?Best solution by Yahoo! Answers
- Can someone explain what fair trade is?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.