簡體   English   中英

如何從鏈接哈希表列表中單獨獲取一個鏈接哈希表

[英]How to get a linkedhashmap individually from a list of linkedhashmaps

我有一張地圖清單,從中我分別需要每張地圖以作進一步的用途。 這是我正在使用的代碼片段

for(int i = 0; i < 5; i++) {
        listOfMaps.add(new LinkedHashMap<String, Double>());
    }

    int j=0;
    while(it.hasNext())
    {
        try
        {
            List<Entry<String,Double>> list1 = new ArrayList<Entry<String,Double>>();

            Map.Entry pairs = (Map.Entry)it.next();
            System.out.println(  pairs.getKey() );

            for (int i = 0; i< ((List<Entry<String, Double>>) pairs.getValue()).size() ; i++)
            {
                String docId = ((List<Entry<String, Double>>) pairs.getValue()).get(i).getKey();
                Double ScoreValue = ((List<Entry<String, Double>>) pairs.getValue()).get(i).getValue();
                listOfMaps.get(j).put(docId, ScoreValue);
            }

我如何才能分別處理它們,我也想確保每張地圖的大小都相同。如何確保列表中的所有地圖的大小都相同。

這是一個小程序,我為您編寫的,我不了解您要如何處理地圖的流程邏輯,所以我創建了一個單獨的流程功能,以便您可以在其中插入邏輯

static List<Map<String, Double>> listOfMaps = new ArrayList<Map<String, Double>>();

    public static void main(String[] args) {
        for (int i = 0; i < 5; i++) {
            Map map=new LinkedHashMap<String, Double>();
            map.put("serial",i);
            putValues(map);
            listOfMaps.add(map);
        }

        int j = 0;
        Iterator<Map<String, Double>> it = listOfMaps.iterator();
        while (it.hasNext()) {


            Map mapItem = (LinkedHashMap) it.next();
            process(mapItem);
            System.out.println("After processing"+mapItem);

            /*System.out.println(pairs.getKey());

            for (int i = 0; i < ((List<Entry<String, Double>>) pairs.getValue())
                    .size(); i++) {
                String docId = ((List<Entry<String, Double>>) pairs.getValue())
                        .get(i).getKey();
                Double ScoreValue = ((List<Entry<String, Double>>) pairs
                        .getValue()).get(i).getValue();
                listOfMaps.get(j).put(docId, ScoreValue);
            }*/
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM