Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/samyam81/anonymous-functions
A lambda expression in Java is a concise way to define an anonymous function that can be used as a method parameter or assigned to a variable.
https://github.com/samyam81/anonymous-functions
cpp csharp functional-programming java
Last synced: 3 days ago
JSON representation
A lambda expression in Java is a concise way to define an anonymous function that can be used as a method parameter or assigned to a variable.
- Host: GitHub
- URL: https://github.com/samyam81/anonymous-functions
- Owner: samyam81
- Created: 2024-01-25T07:55:32.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-21T10:09:56.000Z (8 months ago)
- Last Synced: 2025-01-27T09:14:32.115Z (3 days ago)
- Topics: cpp, csharp, functional-programming, java
- Language: Java
- Homepage:
- Size: 25.4 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Java Lambda Expressions and Functional Interfaces
This repository contains Java code examples demonstrating the usage of lambda expressions and functional interfaces.
## Generic Calculator
The `GenericCalculator` class showcases the usage of generic types with functional interfaces. It includes:
- A generic `calculate` method that takes two operands and a `MathOperation` as parameters.
- An interface `MathOperation` defining the `perform` method for arithmetic operations.
- Implementations of addition, subtraction, multiplication, and division.## Number Filtering
The `Number` class demonstrates how to filter numbers using lambda expressions and functional interfaces. It includes:
- A method `FilterNumbers` that takes a list of numbers and a predicate function to filter numbers.
- Predicate functions `IsPositive` and `IsDivisibleBy3` for filtering positive numbers and numbers divisible by 3.## Vowel Counting
The `VowelMain` class showcases how to count vowels in a string using lambda expressions and Java's `Function` interface. It includes:
- A lambda function `countVowels` to count vowels in a string.
- Usage of the `Function` interface to apply the lambda function to the input string.These examples demonstrate the versatility and simplicity of lambda expressions and functional interfaces in Java for various tasks such as arithmetic operations, filtering data, and text processing.