I’m trying to write a boolean function that returns true or false.
private boolean isExist(Optional<List<Attributes>> attributes) { if (attributes.get().stream().filter(att -> att.getAttributeName().equals("exist") && att.getAttributeValue().equals("true")).count() > 0) { return true; } return false; }
How can I make use of Boolean.parseBoolean
instead att.getAttributeValue().equals("true")
? Is there any advantage of using it?
Answer
I think you can use:
if (attributes.isEmpty()) { return false; } return attributes.get().stream().anyMatch(att -> "exist".equals(att.getAttributeName()) && Boolean.parseBoolean(att.getAttributeValue()) );