Сделать лямбду которая возвращает длину массива, созданного из текста разделенного пробелами

Учусь, делаю домашнее задание. Учим лямбды и вроде все понятно было до этого задания. Вот условия на английском:

Add another method, which accepts String and Function<String, Integer> (accepts String returns Integer.) And make lambda which count of words in String (split by space to array of string, and get array length)

Вот пару моих вариантов которые не работают, уже перепробовал все что было в голове, помогите((

String text3 = "We have to count words of this text";

public static Integer convertStringToInt(String string, Function<String, Integer> function){
    return function.apply(string);

}

convertStringToInt(text3, String.valueOf(text3.split(" ")) -> Array.getLength(text3));
convertStringToInt(text3, String.valueOf(text3.split(" ")) :: length);
convertStringToInt(text3, Array.getLength(String.valueOf(text3.split(" "))) -> .....?????

Ответы (1 шт):

Автор решения: Дмитрий

Если я все верно понял, то все довольно несложно:

public static void main(String[] args) {
    Function<String,Integer> function = str->str.split(" ").length;
    String text = "We have to count words of this text";        
    convertStringToInt(text, function);
}
public static Integer convertStringToInt(String string, Function<String, Integer> function) {
    return function.apply(string);
}
→ Ссылка