用于比较数据集的任何Java集合 [英] Any Java collection to compare datasets

查看:225
本文介绍了用于比较数据集的任何Java集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个数据集,有2个月的学生姓名和分数。

I have 2 datasets for 2 months with student names and scores.

我需要为每个学生提供2月份的分数和他/她的feb分数。

I need to provide the Feb scores for each student and percent change with his/her feb scores.

我可以使用Java集合吗?


样本数据集:

名称Jan_score Feb_score
约翰40 80
玛丽61 81
Jim 52 82
Liz - 84
Tim 94 -

Can i do this with Java collection?

Sample Dataset:

name Jan_score Feb_score John 40 80 Mary 61 81 Jim 52 82 Liz - 84 Tim 94 -

像这样

(名称:John,Feb_score:80,percent changes:100)

(名称:Mary,Feb_score:81,percent change :32.76)

(名称:Jim,Feb_score:82,百分比变化:57.69)

(名称:Liz,Feb_score:84,百分比变化:N / br />
(名称:Tim,Feb_score: - ,percent changes:N / A)

(Name: John, Feb_score: 80, percent change: 100)
(Name: Mary, Feb_score: 81, percent change: 32.76)
(Name: Jim, Feb_score: 82, percent change: 57.69)
(Name: Liz, Feb_score: 84, percent change: N/A)
(Name: Tim, Feb_score: -, percent change: N/A)

推荐答案

HashMap如下,

Create a HashMap as follows,

        HashMap<String, ArrayList<Integer>> studentMap=new HashMap<String, ArrayList<Integer>>();

键是学生的姓名,值是他们的标记列表。 ArrayList中的索引0对每个学生都有1月标记,索引1对每个学生都有feb标记,并继续(如果您有更多)。

Key is the name of the student and the value is their list of marks. index 0 in the ArrayList has the january mark for every student , index 1 has feb mark for every student and continues(If you have more).

如下,

    scores=new ArrayList<Integer>();
    scores.add(40);
    scores.add(80);
    studentMap.put("John", scores);

    scores=new ArrayList<Integer>();
    scores.add(61);
    scores.add(81);
    studentMap.put("Mary", scores);

并显示值,

for(String name : studentMap.keySet())
    {
        ArrayList<Integer> scoreList=studentMap.get(name);

        System.out.println("Name : "+name+"     Jan Score: "+scoreList.get(0)+"     Feb Score : "+scoreList.get(1));
    }

在这之间,您可以添加改善百分比的逻辑。

In between you can add your logic for percentage improvement.

这篇关于用于比较数据集的任何Java集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆