How to count elements from list if specific key present in list using scala? -
i have next list construction -
"disks" : [ { "name" : "a", "memberno" :1 }, { "name" : "b", "memberno" :2 }, { "name" : "c", "memberno" :3 }, { "name" : "d", } ]
i have many elements in list , want check 'memberno', if exists want count of list elements.
e.g. here count 3
how check if key exists , count of elements list using scala??
first create class represent input data
case class disk (name : string, memberno : string)
next load info repository (or other datasource)
val disks: list[disk] = ...
and count
disks.count(d => option(d.memberno).isdefined)
list scala
No comments:
Post a Comment