Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

Sets like in Delphi?

Thread view: 
Vojta - 11 Feb 2006 15:07 GMT
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
Ranganath Kini - 11 Feb 2006 17:29 GMT
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!
Roedy Green - 11 Feb 2006 18:15 GMT
>  TFruit = (ftApple, ftOrange, ftBanana ...);
>  TFruits = set of TFruit;
>
>Is it possible to the same in Java?
see http://mindprod.com/jgloss/enum.html

It is more complex that Delphi, but it can do more powerful thing.s
See also Enumset.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Vojta - 11 Feb 2006 20:04 GMT
Thank you all a lot for your help! Vojta :o)

>>  TFruit = (ftApple, ftOrange, ftBanana ...);
>>  TFruits = set of TFruit;
[quoted text clipped - 4 lines]
> It is more complex that Delphi, but it can do more powerful thing.s
> See also Enumset.
Tris Orendorff - 13 Feb 2006 22:45 GMT
> Hello,
>
[quoted text clipped - 6 lines]
>
> Is it possible to the same in Java?

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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.