我想在添加新节点之前检查节点中是否已存在该节点。
我尝试使用foreach循环来做它。但它没有用。
boolean returnVal = false;
for (Node node : displayGraph) {
if (node.getId().equals(n.getId())){
returnVal = true;
}
else{
returnVal =false;
}
}
如果节点已存在于图表上,我想检索true
只需检查Graph.getNode(String)
返回的内容。如果不存在具有该字符串id的节点,则返回null
:
boolean returnVal = displayGraph.getNode(n.getId()) == null ? false : true;