- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我遇到这个问题,我需要一些东西来将区域代码与电话号码相匹配,最后我需要每个区域代码中的电话号码计数,我想我可以使用 map 。你有什么想法吗?
Example
Given area_code: 351 phone_number:123456
Given area_code: 351 phone_number:1234567
Given area_code: 111 phone_number:678904
Output
351:2 (2 is the count on the numbers)
111:1 (1 is the count on the numbers)
最佳答案
首先,创建一个包含两个字段的类,一个表示区号 (String
),另一个表示电话号码 (String
)。一旦完成,您就可以旋转所需的任意数量的对象;用必要的数据填充它,然后将其存储到列表中。
完成后,您可以使用 groupingBy
收集器计算属于每个组(区号)的电话号码数量,如下所示:
Map<String, Long> resultSet =
myList.stream()
.collect(Collectors.groupingBy(ClassName::getAreaCode, Collectors.counting()));
或者如果您只想打印,那么您可以这样做:
myList.stream()
.collect(Collectors.groupingBy(ClassName::getAreaCode, Collectors.counting()))
.forEach((k, v) -> System.out.println(String.join(":", k, v.toString())));
关于java - 如何获取HashMap中存在对应关系的计数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48235951/
我想检查我的应用程序或系统中是否存在库。在 Java 中,我通常执行 System.loadlibrary,但是有谁知道 C 中类似的相应调用吗? 最佳答案 是dlopen打开一个库,dlsym 从加
我在 typescript 中输入以下内容 export type Excludable = T & { isExcluded?: boolean } 其中过滤值: export type Filte
我最近在我的应用程序中添加了一种方法,可以自动格式化 TextView ,从“50000”到“50,000”,效果绝对完美。现在我遇到的问题是,在我的应用程序中,有多个按钮功能可以从该 TextVie
SELECT * FROM conversations WHERE chatMembers LIKE '%1%'AND chatMembers LIKE '%10%' 对话表 id | chatMem
我正在编写一个需要将 Java Date() 值保存到 MySQL 数据库的 RESTful Web 服务,但是,我不确定 MySQL 中可以保存 Java Date() 的数据类型是什么,或者我是否
同样,在任何 Red Hat 或 JBoss 站点上都没有关于此的信息,所以我在这里问... 我不确定是 13 还是 14。 最佳答案 Mapping the Community versions w
同样,在任何 Red Hat 或 JBoss 站点上都没有关于此的信息,所以我在这里问... 我不确定是 13 还是 14。 最佳答案 Mapping the Community versions w
我曾尝试使用 swift 开发一款利用 iPhone 的 3D 触摸硬件的游戏。然而,当我将我的应用程序提交到 App Store 时,它被拒绝了,因为该游戏无法在 iPad 上玩。 我的问题是,
Qt 的有序关联容器对应项 std::map是QMap , std::set是QSet , 对于无序关联容器 std::unordered_map是QHash . 我应该用什么来代替std::unor
JavaScript 方法 String.fromCharCode() 在以下意义上与 Python 的 unichar() 等效: print unichr(213) # prints Õ on t
正如谷歌在 "Discontinuing support for JSON-RPC and Global HTTP Batch Endpoints" 中提到的那样,Google API 客户端库已重新
我正在使用 MapLayer 和 MapOverlay 在 map 中创建自己的路径/折线,GPS 捕获的所有点都存储在一个结构中,以便我可以访问它们。随时。 现在,我希望路径在用户操作 map (缩
我们使用 Adobe Flash Builder 创建由 Flex 提供支持的交互式 Web 应用程序。现在我们正在寻找替代方案,让我们在 UI 设计和迎合 HTML5 的编码方面拥有同样的开发便
我想知道Android/Java 中类似C#/C++ 中的GetTickCount 方法的相应方法吗? 最佳答案 Android 为 SystemClock.uptimeMillis() .请注意,u
我用 Vue + Phaser 开始了新项目,但是当我尝试加载 Assets 时,this.game.load.image 中的“load”和“add”返回“undefined”。我尝试从 JS 文件
我是一名优秀的程序员,十分优秀!