Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.HashMap;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class Main {

    public static Map<String, List<String>> classify(List<Map<String, Object>> result, String key, String key2) {
        Map<String, List<String>> map = new HashMap<String, List<String>>();
        List<String> values = null;
        for (Map<String, Object> record : result) {
            String mapKey = String.valueOf(record.get(key));
            String mapkey2 = String.valueOf(record.get(key2));
            if (!map.containsKey(mapKey)) {
                values = new LinkedList<String>();
                values.add(mapkey2);
            } else {
                map.get(mapKey).add(mapkey2);
            }
            map.put(mapKey, values);
        }
        return map;
    }
}