Optional::orElse - you have another cup which you will use if the box is empty (or you don't have a cup but act like you do)
Optional::orElseGet - you don't have another cup but you know where to get it (and you throw a fit if you don't get a cup there)
Optional::filter - you only need coffee if it has no sugar
Optional::map - you have a kettle and want to make a cup of coffee
Optional::flatMap - you have a kettle and want to make a cup of coffee but there might be no cups in the cupboard
Optional::ifPresent - do something with a cup
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
other Optional methods
Optional::orElse - you have another cup which you will use if the box is empty (or you don't have a cup but act like you do)
Optional::orElseGet - you don't have another cup but you know where to get it (and you throw a fit if you don't get a cup there)
Optional::filter - you only need coffee if it has no sugar
Optional::map - you have a kettle and want to make a cup of coffee
Optional::flatMap - you have a kettle and want to make a cup of coffee but there might be no cups in the cupboard
Optional::ifPresent - do something with a cup