I need to create a class which does the exact same functionality as a Set does, but for this project I'm not allowed to use the java import for sets.

The only functions I need are adding to the set and removing from a set.

If someone has done this in the past can you please share? Or can someone start me off with the code for how this can be done?

Recommended Answers

All 3 Replies

Set is just an interface that other classes if using it need to implement its methods. Not sure what you want to code there...

Well make a class with a Generic Type:

class mySet<T> {
ArrayList<T> al = new ArrayList<T>();
public void add(T t) {
al.add(t);
}
public void remove (T t) {
al.remove(t);
}
}

Something like this?

Make a list of the functionality you want to give your class. Make a list of the methods you'll need and the data structures to support the data in the set.
Do a little design work and start coding.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.