Database Reference
In-Depth Information
Note
LabelscanbeusedfornodelookupoperationsinCypherqueriesaswell.Thisuseoflabels
will be discussed in
chapter 6
.
Just as in relationship types, node labels are defined using a simple interface with a single
method,
String name()
:
public interface Label {
java.lang.String name();
}
To create a new label, you can simply implement this interface, or, as with relationship
types, use the Java enumeration idiom, which fulfills the
Label
interface contract:
public enum MyLabels implements Label{
MOVIES, USERS
}
The following listing illustrates how you can create labels using the Neo4j Java API.
Listing 3.10. Adding labels to nodes
To add a label, you use the
addLabel()
method on the selected node . To find all
nodes with a given label, you can use the static
getAllNodesWithLabel(Label
label)
method on the
GlobalGraphOperations
class
.