retrieve the list of subsets based on the sequences. - Java java.util

Java examples for java.util:List Filter

Description

retrieve the list of subsets based on the sequences.

Demo Code


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class Main{
    public static void main(String[] argv){
        List records = java.util.Arrays.asList("asdf","java2s.com");
        int attId = 42;
        System.out.println(getDiscreteLists(records,attId));
    }/*from www .j  a va2s .c  o m*/
    /**
     * retrieve the list of subsets based on the sequences.
     */
    public static Map<String, List<Row>> getDiscreteLists(
            List<Row> records, int attId) {
        Map<String, List<Row>> map = new HashMap<String, List<Row>>();
        for (Row record : records) {
            String str = record.getValue(attId);
            if (map.get(str) == null) {
                List<Row> discrete = new ArrayList<Row>();
                discrete.add(record);
                map.put(str, discrete);
            } else {
                map.get(str).add(record);
            }
        }
        return map;
    }
}

Related Tutorials