Sets like in Delphi?

V

Vojta

Hello,

I'm new to Java, can you please give an advice? In Delphi I could do this:

type
TFruit = (ftApple, ftOrange, ftBanana ...);
TFruits = set of TFruit;

Is it possible to the same in Java?

enum Fruit {APPLE, ORANGE, BANANA ...};
???

Thank you:) Vojta
 
R

Ranganath Kini

I haven't worked with Delphi, but Java certainly has set functionality
via java.util.Set interface and related implementations. For example,

Set has the following bulk functions which corelate to set operations:

Suppose s1 ans s2 are instances of java.util.Set, so...

s1.containsAll( s2 ) - Returns true if s2 is a subset of s1
s1.addAll( s2 ) - Transforms s1 into the union of s1 and s2
s1.retainAll( s2 ) - Transforms s1 into the intersection of s1 and s2
s1.removeAll( s2 ) - Transforms s1 into the (asymmetric) set difference
of s1 and s2, i.e. functuion retains all elements of s1 but removes all
elements of s2 from s1

For more information, consult the JavaDocs on the java.util.Set and the
related implementations at:

http://java.sun.com/j2se/1.5.0/docs/api/java/util/Set.html

Hope it helps!
 
T

Tris Orendorff

Hello,

I'm new to Java, can you please give an advice? In Delphi I could do
this:

type
TFruit = (ftApple, ftOrange, ftBanana ...);
TFruits = set of TFruit;

Is it possible to the same in Java?

Yes, you can, with a little work and the java.util.BitSet class.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top