We consider a deck of playing cards in the following format:
Ranks: 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, A
Suits: S - Spade, D - Diamond, H - Heart, C - Club
Every card will be identified by 2 characters E.g. "3S" (3 of Spades), "TC" (10 of Club), "AH" (Ace of Heart).
I want to modify the
getCardsBySuit function in order to
return a Stream with all the cards belonging to that suit.
E.g. for a list that contains "2H", "3S", "TH" and the suit is 'H', the result should be a stream containing "2H" and "TH"
public static Stream<String> getCardsBySuit(List<String> cards, char suit)
{
return null;
}
What I have tried:
public static Stream<String> getCardsBySuit(List<String> cards, char suit)
{
return cards.stream()
.filter(e -> e.startsWith(e, 'S'))
.filter(e -> e.startsWith(e, 'D'))
.filter(e -> e.startsWith(e, 'H'))
.filter(e -> e.startsWith(e, 'C'));
}