# java.util.function

***

1. **Predicate** to check if a string is empty:

```java
Predicate<String> isEmpty = String::isEmpty;
```

2. **Function** to get the length of a string:

```java
Function<String, Integer> length = String::length;
```

3. **Consumer** to print a string:

```java
Consumer<String> print = System.out::println;
```

4. **Supplier** to generate a random number:

```java
Supplier<Integer> randomNumber = () -> (int) (Math.random() * 10);
```

5. **BiFunction** to calculate the area of a rectangle:

```java
BiFunction<Integer, Integer, Integer> area = (width, height) -> width * height;
```

6. **UnaryOperator** to increment a number:

```java
UnaryOperator<Integer> increment = x -> x + 1;
```

7. **BinaryOperator** to add two numbers:

```java
BinaryOperator<Integer> add = (x, y) -> x + y;
```

8. **Comparator** to compare two strings:

```java
Comparator<String> comparator = Comparator.comparing(String::length);
```

9. **Runnable** to create a thread that prints a message:

```java
Runnable runnable = () -> System.out.println("Hello, world!");
```

10. **BiConsumer** to accept two strings and print them:

```java
BiConsumer<String, String> printPair = (x, y) -> System.out.println(x + ", " + y);
```

11. **ToIntFunction** to convert a string to an integer:

```java
ToIntFunction<String> toInt = Integer::parseInt;
```

12. **ToDoubleFunction** to convert a string to a double:

```java
ToDoubleFunction<String> toDouble = Double::parseDouble;
```

13. **ToLongFunction** to convert a string to a long:

```java
ToLongFunction<String> toLong = Long::parseLong;
```

14. **IntPredicate** to check if an integer is even:

```java
IntPredicate isEven = x -> x % 2 == 0;
```

15. **DoublePredicate** to check if a double is greater than 0:

```java
DoublePredicate isPositive = x -> x > 0;
```

16. **LongPredicate** to check if a long is less than 10:

```java
LongPredicate isLessThan10 = x -> x < 10;
```

17. **Consumer** to print a formatted string:

```java
Consumer<String> printFormatted = System.out::printf;
```

18. **BiFunction** to create a pair:

```java
BiFunction<Integer, Integer, Pair<Integer, Integer>> createPair = Pair::of;
```

19. **BinaryOperator** to combine two pairs:

```java
BinaryOperator<Pair<Integer, Integer>> combinePairs = (x, y) -> Pair.of(x.getKey() + y.getKey(), x.getValue() + y.getValue());
```

20. **Supplier** to generate a list of numbers:

```java
Supplier<List<Integer>> generateNumbers = () -> Stream.iterate(1, x -> x + 1).limit(10).toList();
```

21. **Comparator** to compare two lists:

```java
Comparator<List<Integer>> comparator = Comparator.comparingInt(List::size);
```

22. **Consumer** to print a list of numbers:

```java
Consumer<List<Integer>> printNumbers = System.out::println;
```

23. **BiFunction** to calculate the sum of two lists:

```java
BiFunction<List<Integer>, List<Integer>, List<Integer>> sumLists = (x, y) -> {
    List<Integer> result = new ArrayList<>();
    for (int i = 0; i < x.size(); i++) {
        result.add(x.get(i) + y.get(i));
    }
    return result;
};
```

24. **UnaryOperator** to square a number:

```java
UnaryOperator<Integer> square = x -> x * x;
```

25. **BinaryOperator** to multiply two numbers:

```java
BinaryOperator<Integer> multiply = (x, y) -> x * y;
```

26. **Comparator** to compare two numbers by their absolute value:

```java
Comparator<Integer> comparator = Comparator.comparingInt(Math::abs);
```

27. **Supplier** to generate a random boolean:

```java
Supplier<Boolean> randomBoolean = () -> Math.random() < 0.5;
```

28. **Consumer** to print a boolean:

```java
Consumer<Boolean> printBoolean = System.out::println;
```

29. **BiConsumer** to accept two booleans and print them:

```java
BiConsumer<Boolean, Boolean> printBooleanPair = (x, y) -> System.out.println(x + ", " + y);
```

30. **ToIntFunction** to convert a boolean to an integer:

```java
ToIntFunction<Boolean> toInt = x -> x ? 1 : 0;
```

31. **ToDoubleFunction** to convert a boolean to a double:

```java
ToDoubleFunction<Boolean> toDouble = x -> x ? 1.0 : 0.0;
```

32. **ToLongFunction** to convert a boolean to a long:

```java
ToLongFunction<Boolean> toLong = x -> x ? 1L : 0L;
```

33. **IntPredicate** to check if an integer is divisible by 3:

```java
IntPredicate isDivisibleBy3 = x -> x % 3 == 0;
```

34. **DoublePredicate** to check if a double is negative:

```java
DoublePredicate isNegative = x -> x < 0;
```

35. **LongPredicate** to check if a long is positive:

```java
LongPredicate isPositive = x -> x > 0;
```

36. **Consumer** to print an object:

```java
Consumer<Object> printObject = System.out::println;
```

37. **BiConsumer** to accept two objects and print them:

```java
BiConsumer<Object, Object> printObjectPair = (x, y) -> System.out.println(x + ", " + y);
```

38. **Supplier** to generate a list of objects:

```java
Supplier<List<Object>> generateObjects = () -> Stream.iterate(1, x -> x + 1).limit(10).map(Object::new).toList();
```

39. **Comparator** to compare two objects by their class name:

```java
Comparator<Object> comparator = Comparator.comparing(Object::getClass.getName);
```

40. **Predicate** to check if an object is an instance of a particular class:

```java
Predicate<Object> isInstance = o -> o instanceof String;
```

41. **Function** to get the class of an object:

```java
Function<Object, Class<?>> getClass = Object::getClass;
```

42. **Consumer** to print the class of an object:

```java
Consumer<Object> printClass = System.out::println;
```

43. **BiConsumer** to accept two objects and print their classes:

```java
BiConsumer<Object, Object> printClassPair = (x, y) -> System.out.println(x.getClass().getName() + ", " + y.getClass().getName());
```

44. **Supplier** to generate a random object:

```java
Supplier<Object> randomObject = () -> {
    int randomNumber = (int) (Math.random() * 3);
    switch (randomNumber) {
        case 0:
            return new String();
        case 1:
            return new Integer();
        case 2:
            return new Double();
        default:
            throw new RuntimeException("Invalid random number");
    }
};
```

45. **Comparator** to compare two objects by their hash code:

```java
Comparator<Object> comparator = Comparator.comparingInt(Object::hashCode);
```

46. **Predicate** to check if an object is null:

```java
Predicate<Object> isNull = Objects::isNull;
```

47. **Function** to get the string representation of an object:

```java
Function<Object, String> toString = Object::toString;
```

48. **Consumer** to print the string representation of an object:

```java
Consumer<Object> printToString = System.out::println;
```

49. **BiConsumer** to accept two objects and print their string representations:

```java
BiConsumer<Object, Object> printToStringPair = (x, y) -> System.out.println(x.toString() + ", " + y.toString());
```

50. **Supplier** to generate a random list of objects:

```java
Supplier<List<Object>> generateObjects = () -> Stream.iterate(1, x -> x + 1).limit(10).map(x -> {
    int randomNumber = (int) (Math.random() * 3);
    switch (randomNumber) {
        case 0:
            return new String();
        case 1:
            return new Integer();
        case 2:
            return new Double();
        default:
            throw new RuntimeException("Invalid random number");
    }
}).toList();
```
