How to convert below method to Java 8 inline function?

  • A+
Category:Languages

I need to convert below method java 8 inline function. need some expert help and explanation to do this.

@Override public boolean a(final Collection<DoseDetailMutableDTO> detailModels) {     for (DoseDetailMutableDTO dd : detailModels) {          final boolean doseDetailTextScheduled = isDoseDetailTextScheduled(dd, 1);          if (doseDetailTextScheduled) {              return true;          }     }     return false; } 

and Are there any short cut to do this intelj IDE ?

 


You can make use of Stream.anyMatch as:

public boolean a(final Collection<DoseDetailMutableDTO> detailModels) {     return detailModels.stream()                        .anyMatch(dd -> isDoseDetailTextScheduled(dd, 1)); } 

returns true if any elements of the stream match the provided predicate, otherwise false

Edit: (from comments)

The control to learn for such suggested shortcuts on IntelliJ IDEA is Ctrl+Space or on MacOS can use Alt+Enter as well.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: