如何在Java中执行(sql)组(How to perform a group by (sql) in Java)

编程入门 行业动态 更新时间:2024-10-25 16:17:44
如何在Java中执行(sql)组(How to perform a group by (sql) in Java)

我有一个文本文件,如下所示:

code appearance ---------------- j4t8 1 fj89 3 pf6n 1 j4t8 5

我想按照看起来最多的代码进行排序。 正如您所看到的(并且由于我想执行分组),存在重复的代码,因此使用HashMap会出现问题(重复键)。 有任何想法吗?

I have a text file which looks like this:

code appearance ---------------- j4t8 1 fj89 3 pf6n 1 j4t8 5

And I want to sort by the codes which appear the most. As you can see (and since I want to perform a group by) there are duplicate codes, so using HashMap would be a problem (duplicate keys). Any ideas?

最满意答案

不知道这是否是最好的解决方案,但你可以创建一个列表的地图,如下所示:

Map<String, List<Integer>> map = new HahsMap<String, List<Integer>>(); if(map.contains.(key)) { map.get(key).add(new_appearance_value); } else { List<Integer> app = new ArrayList<Integer>(); app.add(new_appearance_value); map.put(key, app); }

地图键将是代码,外观的值将进入列表。

注意:要确定哪些代码具有更多外观,只需检查每个代码列表的大小。

don't know if this is the best solution but you could create a map of a list like this:

Map<String, List<Integer>> map = new HahsMap<String, List<Integer>>(); if(map.contains.(key)) { map.get(key).add(new_appearance_value); } else { List<Integer> app = new ArrayList<Integer>(); app.add(new_appearance_value); map.put(key, app); }

Where the map key would be the code and the values of appearance would go into the list.

Note: to determine which code has more appearances just check for the size of the list of each code.

更多推荐

本文发布于:2023-07-19 20:46:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1186753.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   Java   sql   perform   group

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!