java


How does one Convert a List to Map with Java-8 Streams where Key is the ListValue and the Value is the amount of values of that specific list


This is my list:
List<Card> cards;
my Java-8 stream where i want to create the Map
Map<String, Integer> cardsMap = cards.stream().collect(Collectors.groupingBy(Card::getCardValue, amount of cards that are grouped));
This obviously doesn't work but i am clueless of how i would do it otherwise.
Is this what you meant?
Map<String, Long> cardsMap = cards
.stream()
.collect(Collectors.groupingBy(Card::getCardValue, Collectors.counting()));
It will give you a map from card values to counts of cards with that value in your original list. For example, if you have:
List<Card> cards = Arrays.asList(new Card("4"), new Card("8"), new Card("4"));
(and I know I’ve probably reduced your Card() constructor), the above will map "4" to 2 and "8" to 1.
found the problem, this is how one does it:
Map cardsMap = cards.stream().collect(Collectors.groupingBy(e -> e.getCardValue(), Collectors.counting()));
found answer here:
How to count the number of occurrences of an element in a List

Related Links

Creating new files concurrently [duplicate]
Capturing Buffering playing live Audio Streaming
Using JavaFX in Swing to replace jEditorPame for HTML rendering
org.springframework.batch.item.file.FlatFileParseException:
Running Test Groups in same class parallel
How to make a number triangle java
What difference will static methods in a JAX-RS class make?
Json parsing error using Java
How to import gradle project into STS 3.7.2
How to run cbioportal tomcat war using heroku's webapp-runner.jar
Looking to write info to a file using print writer from button inputs on a simple GUI application
I cannot understand the purpose of using and not using “void”,(what does returning a value mean?" [duplicate]
How to remove “org.restlet.engine.application.StatusInfo” on JSON response
How to print stack trace without error occurance
LibGDX: Problems with getting Bounds
Timeout logs in Rivr Dialogues

Categories

HOME
log4j
blogger
path-finding
homebrew
hashmap
session
octobercms
alfresco
framework7
routes
bookshelf.js
gis
maven-3
leon
ravendb
mouse
in-app-purchase
ios-charts
cloudkit
windows-10-universal
rascal
quickbooks
spring-tool-suite
clojurescript
transformation
oracle-coherence
scichart
intentfilter
mustache.php
lcd
poltergeist
phpfox
ejabberd-module
c++-amp
unboundid
gtrendsr
vsts-build-task
form-data
swisscomdev
elasticsearch-plugin
android-tabhost
pdf-reactor
thin
websphere-mq-fte
angular2-meteor
appcompat
dds
typescript1.8
sqlclient
google-perftools
hittest
lync-client-sdk
orthogonal
crosswalk-runtime
elements
autorest
qpid
gstreamer-0.10
angstrom-linux
rvest
nessus
freelancer.com-api
lib.web.mvc
iis-arr
jsapi
truevault
python-green
dia
sorl-thumbnail
typekit
xcode-6.2
document-classification
jubula
comexception
poller
coverflow
tinn-r
e4x
trusted
google-email-migration
dsn
armcc
getmessage
removeclass
fireworks
doh
xtype
rfc1123
table-footer
inotifycollectionchanged
sql-server-profiler
cxxtest
digest-authentication
sef
kdbg
swing-app-framework
caching-application-block

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App