Printing all Strings from a list by passing in char variable

W.Smith :

I need to print all strings from a list by passing in a char variable.

And I pass in char p when I have something for example like

public static void printStrings(List<String> words, char p)
{

words.stream()
.filter(i -> i.startsWith(p)) 
.sorted()
.forEach(System.out::println);

}

how would I pass in the char variable because I keep getting an error that says

error: incompatible types: char cannot be converted to String

So how would I pass in a char variable without getting an error?

zhh :

String::startsWith can only accept String as argument.

Try

.filter(i -> i.startsWith(Character.toString(p)))

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=89460&siteId=1