Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use java built-in functional interface

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains the "java built-in functional interface how to use", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "java built-in functional interface how to use" it!

1. Predicate is a Boolean function with only one input parameter. The Predicate interface contains a variety of default methods to handle complex logical verbs.

Predicate predicate = (s)-> s.length () > 0; predicate.test ("foo"); / / truepredicate.negate () .test ("foo"); / / false Predicate nonNull = Objects::nonNull;Predicate isNull = Objects::isNull; Predicate isEmpty = String::isEmpty;Predicate isNotEmpty = isEmpty.negate ()

2. The Function interface receives a parameter and returns a single result. By default, multiple functions can be concatenated together.

Function toInteger = Integer::valueOf;Function backToString = toInteger.andThen (String::valueOf); backToString.apply ("123"); / /" 123"

3. The Supplier interface produces results of a given type. Unlike Function,Supplier, there are no input parameters.

Supplier personSupplier = Person::new;personSupplier.get (); / / new Person Thank you for reading, this is the content of "how to use java built-in functional interface". After the study of this article, I believe you have a deeper understanding of how to use java built-in functional interface, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report