Any Java collection for comparing datasets

I have 2 data sets for 2 months with student names and grades.

I need to provide February grades for each student and a percentage change with his / her feb grades.

Can I do this using the Java collection?

Dataset example:

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

The output should look like this:

(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: not determined)
(Name: Tim, Feb_score: -, percent change: not determined)

+4
4

HashMap :

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

- , - . 0 ArrayList , 1 feb ( ).

, ,

    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));
    }

.

+3

Java, . . , , .

+1

( = , value = ). , , .

To calculate the percentage change, follow these steps:

1) Iterations over all elements in the February map (say, the current student is a student)

2) Look for Student rating 'stu' on the January map.

3) Calculate the percentage change.

+1
source

To do this, you can use TreeSet, and you create another class in one package and implement the “Comparator Interface” to compare two objects and pass it when creating TreeSet objects.

+1
source

Source: https://habr.com/ru/post/1538644/


All Articles