Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

java arraylist get number of elements with same parameter

// Example Poker:
// ArrayList of PokerCards (hand)
// 		-> Map with - Suit (parameter of object) as key
// 					- List<PokerCard> (List of objects with that parameter) as value
Map<Suit, List<PokerCard>> map = hand.stream().collect(Collectors.groupingBy(PokerCard::getSuit));

// Now you can get the number of elements for each parameter like that:
map.keySet().forEach(s -> {
	System.out.println(s.name() + " " + map.get(s).size());
});
 
PREVIOUS NEXT
Tagged: #java #arraylist #number #elements #parameter
ADD COMMENT
Topic
Name
1+1 =