Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement the empty set - ∅? [closed]

Assuming that you want to implement set theory concepts such as element, set, collection and relation in Java: How would you represent the empty set ?

Do I mislead myself, if I think of the NULL concept as it is used by the three-valued logic of databases?

like image 396
M4TT4CK Avatar asked Jul 10 '12 13:07

M4TT4CK


People also ask

Is ∅ an empty set?

Empty Set (Null Set) A set that does not contain any element is called an empty set or a null set. An empty set is denoted using the symbol '∅'. It is read as 'phi'.

Is ø an empty set?

A second set could be defined as having only one element by letting that element be the empty set itself (symbolized by {Ø}), a set with two elements by letting them be the two… The empty (or void, or null) set, symbolized by {} or Ø, contains no elements at all.

Is empty set open and closed?

By the definition of topology (https://en.wikipedia.org/wiki/Topology#Mathematical_definition) the empty set is always open and its complement (i.e. the whole other set) is always closed. Therefore is the emtpy set open and closed in every topology.


1 Answers

Use Collections.emptySet():

Returns the empty set (immutable). This set is serializable. Unlike the like-named field, this method is parameterized. This example illustrates the type-safe way to obtain an empty set:

 Set<String> s = Collections.emptySet();   

Implementation note: Implementations of this method need not create a separate Set object for each call. Using this method is likely to have comparable cost to using the like-named field. (Unlike this method, the field does not provide type safety.)

like image 138
Funky coder Avatar answered Sep 27 '22 18:09

Funky coder